[Chapter 21] Reference: Array
Author: David Flanagan
Date: Fri Aug 29 11:13:53 1997

#

| Chapter 21 JavaScript Reference |

# Array Object

## Name

Array Object---built-in support for arrays

## Availability

Navigator 3.0, Internet Explorer 3.0; arrays are available in Navigator 2.0, but the Array object class that supports them is not.

## Constructor

    new Array()
    new Array(size)
    new Array(element0, element1, ..., elementn)

### Arguments

`size`

  The desired number of elements in the array. The returned array will have its `length` field set to `size`.

`element0`, ...`elementn`

  An argument list of two or more arbitrary values. When the `Array()` constructor is invoked with these arguments, the newly created array will be initialized with the specified argument values as its elements, and its `length` field set to the number of arguments.

### Returns

The newly created and initialized array. When `Array()` is invoked with no arguments, the returned array will have a `length` field of 0.

## Properties

`length`

  A read/write integer specifying the number of elements in the array, or, when the array does not have contiguous elements, a number one larger than the index of the last element in the array.

## Methods

`join`

  Convert all array elements to strings and concatenate them.

`reverse`

  Reverse, in place, the order of the elements of an array.

`sort`

  Sort, in place, the elements of an array.

## Description

Arrays are a basic syntactic feature of JavaScript. All JavaScript objects, regardless of their type, may be used as arrays. The dual nature of arrays and objects is discussed in Chapter 8, Arrays, along with full details on the JavaScript syntax for reading and setting array elements.

The Array is a new object type, added in Navigator 3.0, which, along with the usual array capabilities that all JavaScript objects have, also provides additional array functionality: a constructor function for initializing arrays, an automatically updated `length` field that stores the size of the array, and `join()`, `reverse()`, and `sort()` methods that manipulate the elements of an array. See the individual reference pages for details.

## See Also

"Object", Chapter 8, Arrays

Area |  | Array.join()