jQuery Javascript array 'contains' functionality?
- by YourMomzThaBomb
I'm trying to use the jQuery $.inArray function to iterate through an array and if there's an element whose text contains a particular keyword, remove that element. $.inArray is only returning the array index though if the element's text is equal to the keyword.
For example given the following array named 'tokens':
- tokens {...} Object
[0] "Starbucks^25^http://somelink" String
[1] "McDonalds^34^" String
[2] "BurgerKing^31^https://www.somewhere.com" String
And a call to removeElement(tokens, 'McDonalds'); would return the following array:
- tokens {...} Object
[0] "Starbucks^25^http://somelink" String
[1] "BurgerKing^31^https://www.somewhere.com" String
I'm guessing this may be possible using the jQuery $.grep or $.each function, or maybe regex. However, I'm not familiar enough with jQuery to accomplish this.
Any help would be appreciated!