I declared the following function in JavaScript so I can see what is contained within an array.
Array.prototype.contains = function (obj) {
var i = this.length;
while (i--) {
if (this[i] === obj) {
return true;
}
}
return false;
}
Added the above function... now when I do the following, the function is added to the array keys... This can be seen by comparing the output with the console.log lines below.
var obsr = {0: 'hi',1: 'go',3:'sss'};
var keys = Object.keys(obsr);
for (var i in keys){
console.log(i);
console.log(keys[i]);
console.log("----");
}
The output is:
Object {0="hi", 1="go", 3="sss"}
["0", "1", "3"]
0
0
----
1
1
----
2
3
----
contains
function()
----
This is breaking code that uses the Object.keys() function since it's retrieving the function. What am I missing?