Array properties

Provides a reference of the properties of arrays.

Table 1. Array properties
Syntax Effect
array[index]

If index can be converted to a number between 0 and 2e31-1 (see Automatic conversion to a number), array[index] is the value of the index-th element of the array.

Otherwise, it is considered as a standard property access.

If this element has never been set, null is returned.

Example:

Suppose that the array a has been created with

a = new Array("foo", 12, true)

Then:

a[0] –> "foo"

a[1] –> 12

a[2] –> true

a[3] –> null

a[1000] –> null

When an element of an array is set beyond the current length of the array, the array is automatically expanded:

a[1000] = "bar" // the array is automatically expanded.

Unlike other properties, the numeric properties of an array are not listed by the for..in statement.

array.length

The length of array, which is the highest index of an element set in array, plus one. It is always included in 0 to 2e31 -1.

When a new element is set in the array, and its index is greater than or equal to the current array length, the length property is automatically increased.

Example: Suppose that the array a has been created with

a = new Array("a", "b", "c")

Then:

a.length -> 3 a[100] = "bar"; a.length –> 101

You can also change the length of an array by setting its length property.

a = new Array(); a[4] = "foo"; a[9] = "bar" a.length –> 10

a.length = 5 a.length –> 5 a[4] –> "foo" a[9] –> null