In the below JavaScript code :-
var a = [];
for (i in a) {
alert(i);
}
I am getting o/p as - $family, $constuctor, each, clone, clean, invoke, associate, link, contains, append, getlast, getRandom, include, combine, erase, empty, flatten, pick, hexToRgb, rgbToHex.
Can anybody explain why is that so?Has it got to do something with properties of Array objects and if so then why aren't all the properties alerted? Also , if we take a empty object literal like var a = {} , we don't get any o/p.
Now , if I change the above code like :-
var a = [9,2];
for (i in a) {
if (a.hasOwnProperty(i)) {
alert(a.hasOwnProperty(i));
alert(i);
}
}
I get the output as 0 and 1.Why is that so ? Are those the properties of this Array object (which are also the indexes) ?