Array construct

The Array construct creates an array of the elements specified in a parameter, which are listed separated by commas.

Syntax

javascriptlet array = new Array(array elements separated by commas);
javascriptlet array = [array elements separated by commas];

Example

Let's create an array of numbers:

javascriptlet arr = new Array(1, 2, 3, 4);
console.log(arr);

The code execution result:

javascript[1, 2, 3, 4]

Example

Now let's create an array of string elements:

javascriptlet arr = new Array('a', 'b', 'c', 'd');
console.log(arr);

The code execution result:

javascript['a', 'b', 'c', 'd']

See also

  • the Object construct
    that creates a new object