Favorites

JavaScript Array.prototype.length Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.length
JavaScript Array Instance propertyThis property is supported by all modern browsers.
Updated 28th November 2026

The length property gives the number of elements in an array. You can also set it to shorten or extend the array.

Description

The length property of Array instances is the number of elements in the array, or more precisely, one more than the highest index. It updates automatically as you add or remove elements.

You can also set length. Setting it to a smaller number removes elements from the end, and arr.length = 0 empties the array. Setting it to a larger number adds empty slots, which behave differently from slots holding undefined in some methods.

A common use is getting the last element with arr[arr.length - 1], although arr.at(-1) is now a shorter way to do the same thing.

Syntax

array.length

Value

A non-negative integer less than 232. It is one more than the highest index in the array.

Example

const colors = ['red', 'green', 'blue'];
console.log(colors.length);

colors.push('yellow');
console.log(colors.length);

colors.length = 2;     // truncate
console.log(colors);

console.log(colors[colors.length - 1]);

Browser Support

The following information will show you the current browser support for the Array.prototype.length property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee