Array.prototype.contains = function(obj) {
var i = this.length;
while (i–) {
if (this[i] === obj) {
return true;
}
}
return false;
}
or
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i ) {
if (this[i] == element) {
return true;
}
}
return false;
}
It is said that while minus iteration is the fastest method in js, I don’t know if it is true.