Array.of()

Creates a new array from the provided arguments, regardless of their number or type.

Since ES2015 Spec ↗

Syntax

Array.of(...elements)

Parameters

NameTypeRequiredDescription
elements any No Elements used to create the array.

Returns

Array — A new Array instance containing the arguments.

Examples

console.log(Array.of(7));
Output
[ 7 ]
console.log(Array(7).length, Array.of(7).length);
Output
7 1

Notes

Differs from the `Array()` constructor: `Array.of(7)` makes `[7]` while `Array(7)` makes a sparse array of length 7. Useful when a single numeric argument should be an element, not a length.

Browser & runtime support

EnvironmentSince version
chrome 45
firefox 25
safari 9
edge 12
node 4.0

See also