JavaScript Array.prototype.length Property
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.lengthValue
A non-negative integer less than 232. It is one more than the highest index in the array.
Example
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.
Desktop





Tablets & Mobile





