Javascript Array contains(val)
#!/usr/bin/js// ww w.j av a 2 s . c o m arr = [1, 2, 3, 4, 5]; Array.prototype.contains = function (val) { for (var i = 0; i < this.length; i++){ if (this[i] === val){ return true; } } } console.log(arr.contains(3))
Array.prototype.contains = function(val) { return this.indexOf(val) >= 0; };