1
0

More than 1 year has passed since last update.

forEachの中でasync awaitは使えない(コピペ例)

Posted at

forEachの中で非同期処理で詰まったので備忘録として書く

エラー例

      console.log("before_forEach", this.datas);

      this.datas.forEach(async(data) => {
        //非同期処理
      });

      console.log("after_forEach", this.datas);

成功例

      console.log("before_forEach", this.datas);

      for (let data of this.datas){
        //非同期処理
      });

      console.log("after_forEach", this.datas);

forで書き直せば、処理順はうまくいくはず!

参考にしたandより詳しい記事

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0