JavaScript (ES2026) reference · Array Methods

JavaScript Array.fromAsync() Method

Create an array from an async iterable or iterable of promises, awaiting each element. Returns a promise.

JavaScript (ES2026) Since ES2026

Syntax

Array.fromAsync(items, mapFn, thisArg)

Parameters

ParameterDescription
items An async iterable, or an iterable/array-like whose values may be promises.
mapFn optional Called on each awaited element.

Return value

A promise for a new array.

Examples

Collect an async generatorTry it yourself
async function* countdown() {
  yield 3; yield 2; yield 1;
}
console.log(await Array.fromAsync(countdown()));

Output

[ 3, 2, 1 ]
Await a list of promises in orderTry it yourself
const values = await Array.fromAsync([Promise.resolve(1), 2, Promise.resolve(3)]);
console.log(values);

Output

[ 1, 2, 3 ]

Version history

VersionChange
JavaScript ES2026Added