Static Properties and Methods

Array(3) creates three holes, so Array.of(3) exists to create [3]. Array.from() copies any iterable (string, Set, NodeList) or array-like object into a real array, mapping as it goes. Array.fromAsync() (ES2026) does the same for async iterables and returns a Promise.

Static methods of Array
Method Returns
Array.isArray(value) true for arrays, even from other frames
Array.of(...items) New array of the arguments
Array.from(source, mapFn?) New array, optionally mapped
Array.fromAsync(source, mapFn?) Promise for a new array
Array.of(), Array.from() and Array.fromAsync() in an ES moduleJavaScriptLive
console.log(Array(3), Array.of(3), Array.from('abc'));
console.log(Array.from({ length: 4 }, (_, i) => i * i));    // array-like + mapFn
const wait = (ms, v) => new Promise((ok) => setTimeout(ok, ms, v));
async function* pages() { yield ['a', 'b']; yield wait(50, ['c']); }
console.log(Array.from([wait(10, 'x'), 'y']));              // Promises left as-is
console.log(await Array.fromAsync([wait(10, 'x'), 'y']));   // each element awaited
console.log(await Array.fromAsync(pages(), (p) => p.length));

Array.fromAsync() awaits one value at a time, like for await...of (Asynchronous Iteration): ideal for draining a paginated API, but slower than Promise.all() for promises already running. It has been in all major browsers since January

  1. Prefer Array.isArray() to instanceof Array, which fails for arrays from another iframe.