15.4.5.2 array.length

2010-07-07

The length property of arrays is a special setter.

Formally: the length property initially has a value that's always numerically greater than the name of every deletable property who's name is an "array index".

This constraint is applied dynamically.

If you set length to a number whilst the array has an array index with an equal or greater value, all of those indices are deleted.

If you add a property to the array with an array index greater than or equal to length, either implicitly through push or explicitly by setting it, the length property is also incremented (see [[DefineOwnProperty]] (see 15.4.5.1).

The length property has the attributes [[Writable]]:true, [[Enumerable]]:false and [[Configurable]]:false.

One way of detecting whether an object is an array (before Array.isArray was implemented) was to check whether length was enumerable. An expensive but pretty safe method. Of course in ES5 you should use Array.isArray :)