Get to know MDN better
Since January 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Array.fromAsync() static method creates a new, shallow-copied Array instance from an async iterable, iterable, or array-like object.
An async iterable, iterable, or array-like object to convert to an array.
mapFn OptionalA function to call on every element of the array. If provided, every value to be added to the array is first passed through this function, and mapFn's return value is added to the array instead (after being awaited). The function is called with the following arguments:
elementThe current element being processed in the array. If items is a sync iterable or array-like object, then all elements are first awaited, and element will never be a thenable. If items is an async iterable, then each yielded value is passed as-is.
indexThe index of the current element being processed in the array.
thisArg OptionalValue to use as this when executing mapFn.
A new Promise whose fulfillment value is a new Array instance.
Array.fromAsync() lets you create arrays from:
Array.fromAsync() iterates the async iterable in a fashion very similar to for await...of. Array.fromAsync(items) is generally equivalent to the following code, if items is an async iterable or sync iterable:
Array.fromAsync() is almost equivalent to Array.from() in terms of behavior, except the following:
Array.fromAsync() and Promise.all() can both turn an iterable of promises into a promise of an array. However, there are two key differences:
When items is an async iterable where each result's value is also a promise, then those promises are added to the resulting array without being awaited. This is consistent with the behavior of for await...of.
Note: In practice, you will rarely encounter an async iterable that yields promises, because if you implement it using an async generator function, then the yield expression automatically unwraps promises.
When items is a sync iterable or array-like object, both the input and output of mapFn are awaited internally by Array.fromAsync().
When items is an async iterable, the input to mapFn is not awaited, but the output is. Using the same createAsyncIter function as above:
Curiously, this means that Array.fromAsync(createAsyncIter()) is not equivalent to Array.fromAsync(createAsyncIter(), (element) => element), because the latter awaits each yielded value, while the former does not.
Array.fromAsync() awaits each value yielded from the object sequentially. Promise.all() awaits all values concurrently.
Similar to for await...of, if the object being iterated is a sync iterable, and an error is thrown while iterating, the return() method of the underlying iterator will not be called, so the iterator is not closed.
If you need to close the iterator, you need to use a for...of loop instead, and await each value yourself.
| ECMAScript® 2027 Language Specification # sec-array.fromasync |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.