JavaScript (ES2026) reference · Array Methods

JavaScript Array.of() Method

Create a new array from its arguments. Unlike Array(3), Array.of(3) makes [3], not an empty array of length 3.

JavaScript (ES2026) Since ES2015

Syntax

Array.of(element1, /* …, */ elementN)

Parameters

ParameterDescription
elements The elements of the new array.

Return value

A new array.

Examples

Array.of() vs Array()Try it yourself
console.log(Array.of(3), Array(3), Array.of(1, 2, 3));

Output

[ 3 ] [ <3 empty items> ] [ 1, 2, 3 ]
One or zero elementsTry it yourself
console.log(Array.of("a"), Array.of());

Output

[ 'a' ] []

Version history

VersionChange
JavaScript ES2015Added