Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript length Property

JavaScript length Property

Array Object Reference JavaScript Array object

Example

Return the number of elements in an array:

fruits.length;

The result could be

4

Try it »


Definition and Usage

The length property can set or return the number of elements in an array.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the length property.


Syntax

Set the number of elements in an array:

array

.length=

number

Return the length of an array:

array

.length

Technical Details

Return Value: A number indicating the number of elements in the array.
JavaScript version: 1.1

Array Object Reference JavaScript Array object