English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array length Attribute

 JavaScript Array Object

The JavaScript array length property sets or returns the number of elements in the array.

Syntax:

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‹/›

Browser Compatibility

All browsers fully support the length property:

Property
lengthIsIsIsIsIs

Technical Details

Return Value:A Number, representing the number of elements in the array object
JavaScript Version:ECMAScript 1

More Examples

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‹/›

 JavaScript Array Object