We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS



The length property represents an unsigned, 32-bit integer that specifies the number of elements in an array.

Property attributes of length
Writable yes
Enumerable no
Configurable no




The value of the length property is an integer with a positive sign and a value less than 2 to the 32nd power (232).

You can set the length property to truncate an array at any time. When you extend an array by changing its length property, the number of actual elements does not increase; for example, if you set length to 3 when it is currently 2, the array still contains only 2 elements. Thus, the length property says nothing about the number of defined values in the array. See also Relationship between length and numerical properties.


Example: Iterating over an array

In the following example the array numbers is iterated through by looking at the length property to see how many elements it has. The value in each element is then doubled.

var numbers = [1, 2, 3, 4, 5];

for (var i = 0; i < numbers.length; i++) {
  numbers[i] *= 2;
// numbers is now [2, 4, 6, 8, 10]

Example: Shortening an array

The following example shortens the array statesUS to a length of 50 if the current length is greater than 50.

if (statesUS.length > 50) {
  statesUS.length = 50;


Specification Status Comment
ECMAScript 1st Edition. Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.length' in that specification.
ECMAScript 6 (ECMA-262)
The definition of 'Array.length' in that specification.
Release Candidate  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

Document Tags and Contributors

Last updated by: Sevenspade,