JavaScript (ES2026) reference · Array Methods
JavaScript Array length Property
The number of elements in the array. Setting it shortens or extends the array.
JavaScript (ES2026) Since ES1
Syntax
array.length
Return value
An integer: one more than the highest index.
Examples
const fruits = ["apple", "banana", "cherry"];
console.log(fruits.length);
fruits.length = 1; // truncate
console.log(fruits);
Output
3 [ 'apple' ]
const items = [];
if (items.length === 0) console.log("empty");
console.log([1, 2, 3][[1, 2, 3].length - 1]); // last element
Output
empty 3
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
len()· Python
Related
array.at()· Return the element at an index, where negative indexes count from the end: arr.at(-1) is the last element.array.push()· Add one or more elements to the end of the array and return the new length. Changes the array in place.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial