Array() (Constructor)

An Array object constructor.

Availability:

ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Property/method value type:Array object
JavaScript syntax:-new Array()
-new Array(aLength)
-new Array(anItem1, anItem2, anItem3, ...)
Argument list:aLengthAn optional initial length to set the array to.
anItemNA variable number of initial elements to insert into the array.

The Array() constructor is used in a new expression to manufacture a new instance of the Array object.

The arguments passed to the constructor affect the way that the array is initialized.

If no arguments are passed, then an empty array is created. Its length will be zero and it will only have the properties it inherits from its prototype parent.

If it has a single argument, and if that argument is a numeric value that can be realized as an unsigned 32-bit integer with no loss of precision, then it is taken as a length value to initialize the array with. However, according the ECMA standard, a numeric value that is not convertible to a Unit32 should cause a run-time error. This may not be the case with all host implementations and would be considered a minor deviation from the standard. You may find that a single numeric value results in a one-element array containing that value instead of a runtime error. A single argument of non-numeric type results in an array containing one element and having a length value of 1.

If there is more than one argument, then each argument is placed into the array in the order of presentation and the length value set according to the number of arguments provided.

Warnings:

See also:Array object, Array simulation, Array(), Array.prototype, Constructor function, constructor property, Global object, new, Object constant

Cross-references:

ECMA 262 edition 2 - section - 15.1.3.3

ECMA 262 edition 2 - section - 15.4.1

ECMA 262 edition 2 - section - 15.4.2

ECMA 262 edition 2 - section - 15.4.3.1

ECMA 262 edition 2 - section - 15.4.4

ECMA 262 edition 3 - section - 15.4.2

Wrox Instant JavaScript - page - 16