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...

suzyQ
  • 301
  • 1
  • 3
  • 4
  • 1
    `arr = arr.filter(function(a){ return a.indexOf('60894') == -1; });` – Satpal Nov 17 '16 at 13:37
  • Using `splice()` and modifiyng the array in place -> https://jsfiddle.net/dtkjj9d9/ – adeneo Nov 17 '16 at 13:39
  • http://stackoverflow.com/questions/9792927/javascript-array-search-and-remove-string – Satpal Nov 17 '16 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. – suzyQ Nov 18 '16 at 13:41

0 Answers0