Array.fromAsync()
The Array.fromAsync() static method copies items from an async iterable object to make a new array.
Overview
The Array.fromAsync() static method copies items from an async iterable object to make a new array.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 121 | 121 | 115 | 16.4 | 121 | 16.4 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
async function* asyncRange(n) {
for (let i = 0; i < n; i++) yield i;
}
const arr = await Array.fromAsync(asyncRange(5));
// [0, 1, 2, 3, 4] Live demo
asyncgenerator from generate
timebetween or value generateasyncso-s from batch in array create..
PreviewFullscreen
Use cases
Using Array.fromAsync()
The Array.fromAsync() static method copies items from an async iterable object to make a new array.
Cautions
- Not supported in older browsers. Verify your target environments before adopting.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.
Related links
Powered by web-features