Array()
The Array()
constructor is used to create Array
objects.
Syntax
new Array(element0, element1, /* … ,*/ elementN)
new Array(arrayLength)
Array(element0, element1, /* … ,*/ elementN)
Array(arrayLength)
Note:
Array()
can be called with or withoutnew
. Both create a newArray
instance.
Parameters
elementN
- : A JavaScript array is initialized with the given elements, except in the case where
a single argument is passed to the
Array
constructor and that argument is a number (see thearrayLength
parameter below). Note that this special case only applies to JavaScript arrays created with theArray
constructor, not array literals created with the bracket syntax.
- : A JavaScript array is initialized with the given elements, except in the case where
a single argument is passed to the
arrayLength
- : If the only argument passed to the
Array
constructor is an integer between 0 and 232 - 1 (inclusive), this returns a new JavaScript array with itslength
property set to that number (Note: this implies an array ofarrayLength
empty slots, not slots with actualundefined
values).
- : If the only argument passed to the
Exceptions
RangeError
- : Thrown if there's only one argument (
arrayLength
) and its value is not between 0 and 232 - 1 (inclusive).
- : Thrown if there's only one argument (