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 newArrayinstance.
Parameters
elementN- : A JavaScript array is initialized with the given elements, except in the case where
a single argument is passed to the
Arrayconstructor and that argument is a number (see thearrayLengthparameter below). Note that this special case only applies to JavaScript arrays created with theArrayconstructor, 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
Arrayconstructor is an integer between 0 and 232 - 1 (inclusive), this returns a new JavaScript array with itslengthproperty set to that number (Note: this implies an array ofarrayLengthempty slots, not slots with actualundefinedvalues).
- : 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 (