English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The JavaScript array length property sets or returns the number of elements in the array.
Return the length of the array:
array.length
Set the length of the array:
array.length = number
var fruits = ['Apple' 'Mango' 'Banana']; fruits.length;Test and see‹/›
All browsers fully support the length property:
Property | |||||
length | Is | Is | Is | Is | Is |
Return Value: | A Number, representing the number of elements in the array object |
---|---|
JavaScript Version: | ECMAScript 1 |
The index of the last element equals the length property value minus1.
This example uses the length property to display the value of the last element:
var fruits = ['Apple' 'Mango' 'Banana']; fruits[fruits.length - 1;Test and see‹/›