Have a look at the below code:
var a = new Array(); // or just []
a[0] = 0
a['one'] = 1;
a['two'] = 2;
a['three'] = 3;
for (var k in a) {
if (a.hasOwnProperty(k)) {
alert('key is: ' + k + ', value is: ' + a[k]);
}
}
alert(a.length); // 1 is printed
Now i get the following explanation for 1 being printed;
Oddly, the length is reported to be 1, yet four keys are printed. That's because we are manipulating both the array elements and the underlying object.
underlying object ? excuse me , i did't quite understand , can anybody explain please? what is this underlying object ? can anybody emphasis ? please note that my question is't directly why 1 is printed but rather i am asking a slightly wider and difficult question and that is what is the underlying object ?
Found the example HERE
a.push(77);would make it 2 length with value 77 because your [0] gives it 1 length prior and [13] with a push would have made it 15 length