So there is this function
Array.prototype.containsCaseInsensitive = function(obj) {
var i = this.length;
while (i--) {
if (this[i].toUpperCase() === obj.toUpperCase()) {
return true;
}
}
return false;
}
then I create this array:
ary = [0,1,2,3];
for (item in ary){
console.log(ary[item])
}
The output is as follows:
0
1
2
3
function(obj) {
var i = this.length;
while (i--) {
if (this[i].toUpperCase() === obj.toUpperCase()) {
return true;
}
}
return false;
}
Why is the function in the iteration?
Thanks!
Your property is enumerable (although you shouldn’t enumerate the keys of an array using
for ... in ...anyway).On ES5 compatible browsers you can safely add that function as a non-enumerable property using
Object.defineProperty: