Section 24.6. Array: built-in support for arrays


24.6. Array: built-in support for arrays

ECMAScript v1: Object Array

24.6.1. Constructor

 new Array( ) 

new Array(size)

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

24.6.1.1. Arguments

size

The desired number of elements in the array. The returned array has 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 is initialized with the specified argument values as its elements and its length field set to the number of arguments.

24.6.1.2. Returns

The newly created and initialized array. When Array( ) is invoked with no arguments, the returned array is empty and has a length field of 0. When invoked with a single numeric argument, the constructor returns an array with the specified number of undefined elements. When invoked with any other arguments, the constructor initializes the array with the values specified by the arguments. When the Array( ) constructor is called as a function, without the new operator, it behaves exactly as it does when called with the new operator.

24.6.1.3. Throws

RangeError

When a single integer size argument is passed to the Array( ) constructor, a RangeError exception is thrown if size is negative or is larger than 232-1.

24.6.2. Literal Syntax

ECMAScript v3 specifies an array literal syntax. You may also create and initialize an array by placing a comma-separated list of expressions within square brackets. The values of these expressions become the elements of the array. For example:

 var a = [1, true, 'abc']; var b = [a[0], a[0]*2, f(x)]; 

24.6.3. 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. Changing the value of this property truncates or extends the array.

24.6.4. Methods


concat( )

Concatenates elements to an array.


join( )

Converts all array elements to strings and concatenates them.


pop( )

Removes an item from the end of an array.


push( )

Pushes an item to the end of an array.


reverse( )

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


shift( )

Shifts an element off the beginning of an array.


slice( )

Returns a subarray slice of an array.


sort( )

Sorts, in place, the elements of an array.


splice( )

Inserts, deletes, or replaces array elements.


toLocaleString( )

Converts an array to a localized string.


toString( )

Converts an array to a string.


unshift( )

Inserts elements at the beginning of an array.

24.6.5. Description

Arrays are a basic feature of JavaScript and are documented in detail in Chapter 7.

24.6.6. See Also

Chapter 7




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net