In the first case, you create an array object that supports the length property when accessing an integer, non-negative property (index).
In the second case, you created a regular object that inherits an Array prototype. Using [] in this object matches any object and simply sets regular properties on it.
var arr1 = new Array(); // or var arr1 = []; arr1[0] = 0; arr1['foo'] = 3; // arr1 has a length of 1 because 0 is an array index and 'foo' is a regular property. var arr2 = Object.create(Array.prototype); arr2[0] = 0; arr2['foo'] = 3; // arr2 has a length of 0 because both 0 and 'foo' are regular properties.
The ECMAScript 5 language specification describes how length supported in section 15.4 .
Array objects give a special approach to a specific class of property names. The name of the P property (as a String value) is the index of the array if and only if ToString (ToUint32 (P)) is equal to P and ToUint32 (P) is not equal to 2 ^ (32-1).
[...]
In particular, whenever a property whose name is an array index, the length property has changed, if necessary, to be something larger than the numerical value of this array index;
source share