This is because arrays in Javascript are just objects with some syntax sugar highlighted.
For comparison:
var arr = [];
arr[0] = 'foo';
arr['1'] = 'bar';
console.log(arr['0']);
console.log(arr[1]);
... to:
var obj = {};
obj[0] = 'foo';
obj['1'] = 'bar';
console.log(obj['0']);
console.log(obj[1]);
Basically, it Arrayis a type Object, with array-defined methods and non-enumerable properties, such as lengththat can be created using the selected abbreviated syntax[ items... ]
, , , ( , . ).
:
var obj = {};
obj[1.5] = 'foo';
console.log('1.5' in obj);
console.log(obj[1.5]);
var arr = [];
arr[0.5] = 'foo';
console.log('0.5' in arr);
console.log(arr[0.5]);
arr[0] = 'bar';
arr[1] = 'baz';
console.log(arr.length);
console.log(Object.keys(arr));