Object.prototype.isInArray = function(myArray){is so convenient
for (var i=0; myArray.length > i; i++) {
if(myArray[i] == this){
return true;
}
}
return false;
}
if (myObj.isInArray(myArray)) {or with:
Array.prototype.contains = function(myString){They can really backfire and slap you in the face if you're doing work that involves creating objects or arrays and examining their contents. So, I'm back to the prosaic but safe:
for (var i=0; this.length > i; i++) {
if(myString == this[i]){
return true;
}
}
return false;
}
if (myArray.contains(myObj)) {
function arrayContains(anArray, anItem) {Which most people would have been using all along anyway.
for (var i = 0; anArray.length > i; i++) {
if (anItem == anArray[i]) return true;
}
return false;
}
if (arrayContains(myArray, myObj)) {