JavaScript for await...of Statement
The for await...of statement loops over values that arrive asynchronously, such as from an async generator or a list of promises, waiting for each one.
Description
The for await...of statement creates a loop over async iterables, such as async generators and readable streams, as well as ordinary iterables of promises. Each iteration waits for the next value before running the body, so items are processed one at a time, in order.
It can only be used where await is allowed: inside an async function or at the top level of a module. To process promises in parallel rather than one by one, use Promise.all().
The loop works with any object that implements Symbol.asyncIterator, which includes async generators and, in modern browsers, ReadableStream, so you can process a fetch() response body chunk by chunk. If you break out of the loop or an error is thrown inside it, the iterator's return() method is called so it can clean up, for example by closing a stream.
Syntax
for await (const item of asyncIterable) {
statements
}Example
Browser Support
The following information will show you the current browser support for the for await...of statement. Hover over a browser icon to see the version that first introduced support for this statement.
Desktop





Tablets & Mobile





