I have a string array and one string. I'd like to test this string against the array values and apply a condition the result - if the array contains the string do "A", else do "B".
How can I do that?
I have a string array and one string. I'd like to test this string against the array values and apply a condition the result - if the array contains the string do "A", else do "B". How can I do that? |
|||||||||||
|
There is an
If you need to support old IE browsers, you can use polyfill this method using the code in the MDN article. |
|||
|
You can use the
with the following results:
|
|||
|
|
|||
|
and then you can use following code to search in array x
|
|||
|
This will do it for you:
I found it in Stack Overflow question JavaScript equivalent of PHP's in_array(). |
|||||||||
|