jQuery Javascript array 'contains' functionality?
Posted
by YourMomzThaBomb
on Stack Overflow
See other posts from Stack Overflow
or by YourMomzThaBomb
Published on 2010-04-06T22:00:00Z
Indexed on
2010/04/06
22:03 UTC
Read the original article
Hit count: 550
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!
© Stack Overflow or respective owner