Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The length data property of an Array instance represents the number of slots in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array. It may be greater than the number of elements if the array is sparse.
A nonnegative integer less than 232.
| Writable | yes |
| Enumerable | no |
| Configurable | no |
The value of the length property is a nonnegative integer with a value less than 232.
The array object observes the length property, and automatically syncs the length value with the array's content. This means:
When length is set to a bigger value than the current length, the array is extended by adding empty slots, not actual undefined values. Empty slots have some special interactions with array methods; see array methods and empty slots.
See also Relationship between length and numerical properties.
In the following example, the array numbers is iterated through by looking at the length property. The value in each element is then doubled.
The following example shortens the array numbers to a length of 3 if the current length is greater than 3.
Setting length to a value greater than the current length creates a sparse array.
The length property is automatically updated by the array when elements are added beyond the current length. If the length property is made non-writable, the array will not be able to update it. This causes an error in strict mode.
| ECMAScript® 2027 Language Specification # sec-properties-of-array-instances-length |
Enable JavaScript to view this browser compatibility table.
This page was last modified on May 2, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.