Insert item into array after a specific item, if it exists #1520
mikefarah
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Say you have an array like:
And you want to place an item after "foobaz", if it's there. You can do:
Explanation:
with
the item you want to place the new after after, in this case, its "foobaz" in the "cool" array. If the item doesn't exist, thewith
block won't do anythingwith
block, we get the index of that item, and save it as$i
["x"]
into the middle.Beta Was this translation helpful? Give feedback.
All reactions