The `for await...of` 语句在异步或者同步可迭代对象上（包括 `String`，`Array`，`Array`-like 对象（比如`arguments` 或者`NodeList`)，`TypedArray`，`Map`， `Set`和其他对象等等）创建一个迭代循环，调用自定义迭代钩子，并为每个不同属性的值执行语句。

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

## 语法

    for await (variable of iterable) {
      statement
    }

`variable`
  在每次迭代中，将不同属性的值分配给变量。
`iterable`
  被迭代枚举其属性的对象。

### 迭代异步可迭代对象

你还可以迭代一个明确实现异步迭代协议的对象：

    var asyncIterable = {
      [Symbol.asyncIterator]() {
        return {
          i: 0,
          next() {
            if (this.i < 3) {
              return Promise.resolve({ value: this.i++, done: false });
            }

            return Promise.resolve({ done: true });
          }
        };
      }
    };

    (async function() {
       for await (num of asyncIterable) {
         console.log(num);
       }
    })();

    // 0
    // 1
    // 2

### 迭代异步生成器

异步生成器已经实现了异步迭代器协议, 所以可以用 `for await...of`循环。

    async function* asyncGenerator() {
      var i = 0;
      while (i < 3) {
        yield i++;
      }
    }

    (async function() {
      for await (num of asyncGenerator()) {
        console.log(num);
      }
    })();
    // 0
    // 1
    // 2

## 规范

Specification | Status | Comment
--- | --- | ---
ECMAScript Latest Draft (ECMA-262) ECMAScript Language: The for-in, for-of, and for-await-of Statements | Draft |

## 浏览器兼容

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

| Desktop | Mobile | Server
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | Node.js
`for await...of` Experimental | Chrome Full support 63 | Edge No support No | Firefox Full support 57 | IE No support No | Opera Full support 50 | Safari Full support 11 | WebView Android Full support 63 | Chrome Android Full support 63 | Edge Mobile No support No | Firefox Android ? | Opera Android Full support 50 | Safari iOS ? | Samsung Internet Android ? | nodejs ?

### Legend

Full support
  Full support
No support
  No support
Compatibility unknown
  Compatibility unknown
Experimental. Expect behavior to change in the future.
  Experimental. Expect behavior to change in the future.

## 相关链接

- `Statements/for...of`