Array.length (Property)

The number of elements in an array.


ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-myArray.length

The length property of an array indicates one more than the maximum numeric index value that has currently been used. This is because Array elements start indexing from zero rather than one.

Note that this is not necessarily a count of the exact number of elements in the array just an indication of its range of index values.

Whenever a property is added whose name is an array index, the length property is recomputed to allow the length of the array to contain the new element that was added.

Furthermore, when the length value is set explicitly, it may truncate the array and any properties whose name is a numeric value that falls outside the bounds indicated by the length value will be deleted.

This does only affect properties that belong to an Array object itself though. Any properties that are inherited from a parent or prototype are unaffected.

The maximum value for an Array length is 4,294,967,295. This is because a 32 bit integer is used to index the array. Arrays of this length are unlikely to be encountered often! A web page containing an array of that size could take several weeks to download, that is assuming you had 4 GBytes of memory available and that your web browser could address that much storage.

Although this property is marked as ReadOnly, there are some sub-classes of the Array object that allow you to modify the length property directly.


See also:Array index delimiter ([ ]), Array object, Array.constructor, Array.prototype, Collection.length, length, NodeList.length

Property attributes:

ReadOnly, DontDelete, DontEnum.

insert figure 0012


ECMA 262 edition 2 - section - 15.4.2

ECMA 262 edition 2 - section -

ECMA 262 edition 2 - section -

ECMA 262 edition 3 - section -

Wrox Instant JavaScript - page - 16