JavaScript new Array()

Definition and usage

new Array() Constructor is used to create an array object.

Instance

Example 1

// Create an array
const cars = new Array(["Saab", "Volvo", "BMW"]);

Try it yourself

Example 2

Create an empty array and add values:

// Create an array
const cars = new Array();
// Add values to the array
cars.push("Saab");
cars.push("Volvo");
cars.push("BMW");

Try it yourself

Example 3

Without using new Array() Methods to create an array:

// Create an array
const cars = ["Saab", "Volvo", "BMW"];

Try it yourself

Syntax

new Array(iterable)

Parameter

Parameter Description
iterable Required. An iterable object containing values.

Return value

Type Description
array New array object.

Browser support

new Array() Is ECMAScript1 (JavaScript 1997) feature.

It is supported in all browsers:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
supports supports supports supports supports supports