0

I have an array called arr[].
I want to remove an array item (so I guess splice) that contains certain text.
So say one of the array items is:
"this is the array item 60894 thank you"
I want to be able to just put in 60894 and have that entire item removed from the array.
I know this involves splice, and maybe indexOf, but I can't seem to get the syntax just right.
I've found other solutions that show a loop through the entire array; just wondering if I can do a one-off line instead of that.
Thanks...

4
  • 1
    arr = arr.filter(function(a){ return a.indexOf('60894') == -1; }); Commented Nov 17, 2016 at 13:37
  • Using splice() and modifiyng the array in place -> jsfiddle.net/dtkjj9d9 Commented Nov 17, 2016 at 13:39
  • stackoverflow.com/questions/9792927/… Commented Nov 17, 2016 at 13:39
  • @Satpal, thank you for the SO link. However, the original question there appeared to suggest that the OP knew exactly what the element in the array was, to be removed. in this case, we know part of the text but not the exact complete text of the array element. I'll try out the single line you have posted here, and thank you for your help. Commented Nov 18, 2016 at 13:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.