var myArray = new Array();
myArray['112'] = 0;
myArray.length
Why is length 113 in above sample? Shouldn’t '112' add a object property for the array and create something similar to myArray = {"112":0}?
Besides this, why is the length 113 and not 1? Since myArray actually only contains 1 value
Consider this simple example:
The number 3 is used to assign the property name, but it is converted to a string and used as a standard property name (i.e. the string “3”).
Adding a property named “3” has created one property and set the length to 4 since the length is always set to one more than the largest non-negative integer property name.
No other property is created, the array is “sparse”, i.e. it doesn’t have sequentially named (numbered) members. A for..in loop can also be used to see that there is only one property.