Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
或
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}
据说while减迭代是js里最快的一种方法,不知道是不是真的,出自
http://stackoverflow.com/questions/237104/javascript-array-containsobj