Just loop the elements in the array and find the value. This is what you need to do anyway, even if you use some kind of method for this. By looping yourself, you can easily get out of the loop as soon as you find a match that on average reduces the number of items you need to check in half.
for (var i=0; i<theArray.length; i++) {
if (theArray[i] == theString) {
theFunction();
break;
}
}
Guffa source
share