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
| Parameter | Description |
|---|---|
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
async function* countdown() {
yield 3; yield 2; yield 1;
}
console.log(await Array.fromAsync(countdown()));
Output
[ 3, 2, 1 ]
const values = await Array.fromAsync([Promise.resolve(1), 2, Promise.resolve(3)]);
console.log(values);
Output
[ 1, 2, 3 ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2026 | Added |
Related
Array.from()· Create a new array from an iterable or array-like object, with an optional function to map each element.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial