What is Javascript array constructor?
The Array() constructor is used to construct Array objects.
Prototype
//literal constructor
[element1, element2, ..., elementn]
//construct from elements
new Array(element1, element2, ..., elementN)
//construct from arrayLength
new Array(arrayLength)
Parameters
-
elementN: An array is initialized with the given elements (elementN), except in the case where only one element is provided and that one element is also a number. However, if an array is constructed using the[]operator, then the previous rule does not apply. -
arrayLength: If the argument is only one element that is also a number between 0 and 2^32 - 1 inclusive, an array object is created with the length property set toarrayLength.
Code
//using bracket operatorconst array1 = [1, 4, 7, 0]//using elementsconst array2 = new Array(1, 4, 7, 0)//using arrayLengthconst array3 = new Array(10)console.log(array1)console.log(array2)console.log(array3)
The above code shows the examples of array constructors used in each of the three contexts. Note that array3 is constructed with empty spaces instead of undefined objects.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved