Hi,
Here is the JavaScript code to check Array contains an item in JavaScript.
var vArrValues = ["1", "2", "3", "4"];
// Check Array Contains Values
Array.prototype.contains = function (element) {
return this.indexOf(element) > -1;
};
return true;
}
else {
return false;
}
}
CheckArrayContaintsValue("1"); // Returns True
CheckArrayContaintsValue("5"); // Returns False
Hope this helps.
--
Happy Coding.
Gopinath
Here is the JavaScript code to check Array contains an item in JavaScript.
var vArrValues = ["1", "2", "3", "4"];
// Check Array Contains Values
Array.prototype.contains = function (element) {
return this.indexOf(element) > -1;
};
function CheckArrayContaintsValue(vValue) {
if (vArrValues.contains(vValue)) {return true;
}
else {
return false;
}
}
CheckArrayContaintsValue("1"); // Returns True
CheckArrayContaintsValue("5"); // Returns False
Hope this helps.
--
Happy Coding.
Gopinath
No comments:
Post a Comment