This question already has an answer here:
- array.contains(obj) in JavaScript 19 answers
Can someone tell me how to detect if "specialword"
appears in an array? Example:
categories: [
"specialword"
"word1"
"word2"
]
This question already has an answer here:
Can someone tell me how to detect if
|
||||
|
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
jQuery offers
Note that inArray returns the index of the element found, so The pure Javascript option requires looping through the elements of the array manually, at least as a backup. |
|||||||||||
|
You really don't need jQuery for this!
or
It's worth noting that jQuery's indexOf(...) function will work in IE < 9; |
|||||||||||||
|
Just use a for loop
|
|||
|
Here you go:
This function returns a positive integer (the array index of the given value), or Live demo: http://jsfiddle.net/simevidas/5Gdfc/ You probably want to use this like so:
|
||||
|
I don't like
Similarly, you could wrap
|
||||
|