CKTIS / JavaScript
Array.of: an array of the exact supplied values
Array.of creates a new array where every argument becomes one element, including a single numeric argument.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
Array.of(...items)Array.of(...items) creates a result whose length equals the argument count and copies each argument to the corresponding index. It returns a new array and does not flatten iterables or nested arrays.
The key difference from Array(3) is unambiguous numeric handling: Array.of(3) is [3], while the one-number constructor creates three empty slots. No arguments produce an empty array, and undefined remains an ordinary element.
The method is generic: Array.of.call(C, ...) attempts to construct C with the item count. An unusual constructor can change the result type or throw. The example demonstrates safe creation of a one-element numeric array.
Examples
const ofResult = Array.of(3);
const constructorResult = Array(3);
console.log(ofResult.length, ofResult[0]);
console.log(constructorResult.length, 0 in constructorResult);Result
1 3 3 false