length Property

Top  Previous  Next

Gets or sets the number of elements in the array.

Syntax

array.length

Property Value

The number of elements in the array.

Remarks

If you assign a new value to length, the array will grow or shrink if needed. Any new elements created will be initialized to the value undefined. Any elements that had an index greater than or equal to the new length will be discarded.

Examples

var ary, res;

ary = Array(1,true,"test");

res = ary.length// return 3

ary.length = 2;

res = ary.join();// returns "1,true"