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
| Parameter | Description |
|---|---|
elements |
The elements of the new array. |
Return value
A new array.
Examples
console.log(Array.of(3), Array(3), Array.of(1, 2, 3));
Output
[ 3 ] [ <3 empty items> ] [ 1, 2, 3 ]
console.log(Array.of("a"), Array.of());
Output
[ 'a' ] []
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
Related
Array.from()· Create a new array from an iterable or array-like object, with an optional function to map each element.Array.isArray()· Return true if a value is an array. More reliable than typeof, which reports 'object' for arrays.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial