Below is my code to check if a value exists in an array:
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] == obj) {
return true;
}
}
return false;
}
This is my code for array values and function call:
arrValues = ["Sam","Great", "Sample", "High"]
alert(arrValues.contains("Sam"));
The function always returns false. Can anyone tell me what I’m doing wrong here?