Widely availableSupported across all major browsers. Safe to use in production.

Overview

Asynchronous iterator objects, such as those returned by promises or generator functions, are iterable with the for await .. of loop.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
63
79
57
11.1
63
11.3

The [Symbol.asyncIterator]() method of AsyncIterator instances implements the async iterable protocol and allows built-in async iterators to be consumed by most syntaxes expecting async iterables, such as for await...of loops. It returns the value of this, which is the async iterator object itself.

63
79
57
11.1
63
11.3

The Symbol.asyncIterator static data property represents the well-known symbol Symbol.asyncIterator. The async iterable protocol looks up this symbol for the method that returns the async iterator for an object. In order for an object to be async iterable, it must have a [Symbol.asyncIterator] key.

63
79
57
11.1
63
11.3
Other

The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used in contexts where await can be used, which includes inside an async function body and in a module.

63
79
57
12
63
12
Statement
async iterators

async iterators

63
12
57
7
63
7
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
// for await...of loop
for await (const chunk of readableStream) {
  process(chunk);
}

Live demo

for await...of Basics

Iterate. with Symbol.asyncIterator implementationobject for await...of.

PreviewFullscreen

Array. Promise Sequentialprocessing

sequential. with Promise Array for await...of.

PreviewFullscreen

Normal iterator and. Comparison

Symbol.iterator and Symbol.asyncIterator. Compare usage.

PreviewFullscreen

Use cases

  • Using Async iterators and the for await..of loop

    Asynchronous iterator objects, such as those returned by promises or generator functions, are iterable with the for await .. of loop.

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features