This question already has an answer here:
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?
This question already has an answer here: 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? |
|||||||||||||||||
marked as duplicate by Bergi May 17 '14 at 20:16This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
|||||||||||||||||
|
There is an
If you need to support old IE browsers, you can polyfill this method using the code in the MDN article. |
||||
|
You can use the
with the following results:
|
|||||
|
|
|||
|
Create this function prototype:
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(). |
|||||||||
|