offline version v3


15 of 264 menu

Array construct

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

Syntax

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

Example

Let's create an array of numbers:

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

The code execution result:

[1, 2, 3, 4]

Example

Now let's create an array of string elements:

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

The code execution result:

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

See also

  • the Object construct
    that creates a new object
enru