I have an array:
array = [..., "Hello", "World", "Again", ...]
How could I check if "World" is in the array? Then remove it if it exists? And have a reference to "World"?
Sometimes maybe I wanna match a word with a regexp and in that case I won't know the exact string so I need to have a reference to the matched String. But in this case I know for sure it's "World" which makes it simpler.
Thanks for the suggestions. I found a cool way to do it:
http://documentcloud.github.com/underscore
pop() function: This method is use to remove elements from the end of an array. shift() function: This method is use to remove elements from the start of an array. splice() function: This method is use to remove elements from the specific index of an array.
Array elements can be deleted using the JavaScript operator delete . Using delete leaves undefined holes in the array. Use pop() or shift() instead.
filter()
is also an option:
arr = [..., "Hello", "World", "Again", ...] newArr = arr.filter (word) -> word isnt "World"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With