array.contains(obj) in JavaScript - Stack Overflow:

As others have said, the iteration through the array is probably the best way, but it has been proven that a decreasing while loop is the fastest way to iterate in JavaScript. So you may want to rewrite your code as follows:

function contains(a, obj) {
var i = a.length;
while (i--) {
if (a[i] === obj) {
return true;
}
}
return false;
}


Speed savings because you're not checking i against a value. i against a.length requires a lookup each time. i against len, where len is precached with len=a.length still looks up len. This simply evaluates i.