Array

An array with integer indexing and a length property.

Methods:

Array, concat, join, pop, push, reverse, shift, slice, sort, splice, toLocaleString, toSource, toString, unshift

Objects:

Number

Property Listing

Property

Type

Access

Description

length

Number

read/write

The length of the array

Method Listing

Constructor

Array Array (length:Number, [element:Varies])

Creates and returns a new array.

Takes any number of parameters, which become the elements of the array, or a single value which becomes the length of an empty array. Note that you cannot create a one-element array, as the single parameter value is interpreted as the length. Returns the new array.

Parameter

Type

Description

length

Number

If no other parameters are passed, the initial length of the empty array.

Otherwise, the first element.

element

Varies

If there is more than one parameter, the array is initialized with the given parameters.

Array concat (value:Varies)

Returns a new array created by concatenating the given values to the end of the original array.

The original array is unchanged. If an array is provided as a parameter to concat(), each of its elements are appended as separate array elements at the end of the new array. Returns a new array, the result of concatenation the given values to the end of the original array.

Parameter

Type

Description

value

Varies

Any number of values to be added to the end of the array.

Can also be arrays.

String join ([delimiter:String])

Joins all elements of the array into a string; optionally, each element is separated by delimiter.

Returns the string containing the joined elements and delimiters.

Parameter

Type

Description

delimiter

String

A string used to separate each element of the array.

If omitted, the array elements are separated with a comma.

Varies pop ()

Removes the last element from the array, decreases the length by 1, and returns the value of the element.

Returns the value of the deleted array element.

Number push (value:Number)

Places one or more values onto the end of the array and increases length by n.

Returns the new length of the array.

Parameter

Type

Description

value

Number

Any number of values to be pushed onto the end of the array.

Array reverse ()

Reverses the order of the elements in the array.

Returns the reversed array.

Varies shift ()

Removes the first element from the array, decreases the length by 1, and returns the value of the element.

Returns the value of the deleted array element.

Array slice ()

Creates a new array, which contains a subset of the original array's elements.

The slice begins with the index start, and continues up to, but not including the index, end. If start or end is a negative number, the indexed is resolved counting backwards from the end of the array resulting in the element array[array. length + negativeIndex]. Returns a new array containing elements array[start] through array[end-1].

undefined sort (userFunction:Function)

Sorts the elements of the array in place, using the given function to compare to elements.

If no function is provided, the elements are sorted alphabetically. Returns no return value.

Parameter

Type

Description

userFunction

Function

A user-supplied function of the form userFunction(a, b) which returns less than 0 if a is greater than b, 0 if a and b are equal, and greater than 0 if b is greater than a.

Array splice (start:Number, [num:Number], [value:Varies])

Removes num elements from the array beginning with index, start.

Optionally insert new elements beginning at index start. To ensure contiguity, elements are moved up to fill in any gaps. Returns a new array containing any elements deleted from the original array.

Parameter

Type

Description

start

Number

The index of the first element to remove. Negative values are relative to the end of the array.

num

Number

The number of array elements to remove, including start. If omitted, all elements from array index start to the end of the array are removed.

value

Varies

A list of one or more values to be added to the array starting at index start.

Must specify a value for num, to use this argument.

String toLocaleString ()

Converts an array to a string and returns the string (localized).

String toSource ()

Creates a string representation of this object that can be fed back to eval() to re-create an object. Works only with built-in classes.

String toString ()

Converts an array to a string and returns the string.

Yields the same result as array. join() when called without a parameter. Returns a comma-separated list of all the elements of the array.

Number unshift (value:Varies)

Adds one or more elements to the beginning of the array.

Returns the new array length.

Parameter

Type

Description

value

Varies

The values of one or more elements to be added to the beginning of the array.