Static Properties and Methods

Array.from()

Creates a new Array instance from an iterable.Array.from(obj, mapFn, thisArg) has the same result as Array.from(obj).map(mapFn, thisArg), except that it does not create an intermediate array.

Array.isArray()

Returns true if a variable is an array, if not false.

Array.of()

Creates a new Array instance with a variable number of arguments, regardless of the number or type of the arguments.


var a = Array(3);
console.log(a.length);
console.log(Array.isArray(a));

a = Array.of(3);
console.log(a.length);

b = a; // passed by value
c = Array.from(a); // passed by value
delete a;
console.log(b);
console.log(c);

console.log(Array.from('abc'));
console.log(Array.from(new Set(['foo', window])));
console.log(Array.from(new Map([[1, 2], [2, 4], [4, 8]])));
console.log(Array.from([1, 2, 3], x => x + x));
console.log(Array.from({length: 5}, (v, i) => i)); // (‘duck typing’ faking array)

3 true 1 [3] [3] ['a', 'b', 'c'] ['foo', window] [[1, 2], [2, 4], [4, 8]] [2, 4, 6] [0, 1, 2, 3, 4]

Array.fromAsync(asyncOrSyncIterable, mapFn, thisArg)

Added in ECMAScript 2026 as the natural async counterpart to Array.from(), returns a Promise for an array collected from an async iterable (5.8) — awaiting each yielded value/promise in turn — or, just as usefully, from a plain synchronous iterable whose values happen to be Promises, which Array.from() alone would collect as unresolved Promise objects rather than their eventual values.


async function* asyncNumbers() {
  yield 1;
  yield await Promise.resolve(2);
  yield 3;
}

const a = await Array.fromAsync(asyncNumbers());
console.log(a);

const b = await Array.fromAsync([Promise.resolve('x'), Promise.resolve('y')]);
console.log(b);   // not [Promise, Promise], as plain Array.from() would give

[1, 2, 3] ['x', 'y']