DEV Community

Discussion on: Dealing with Promises In an Array with async/await

Collapse
 
4umfreak profile image
Mark Voorberg

Thanks for this. When you write the "explainer" article for number 3, please contrast it with an old-school for loop. I'm interested to see if your opinion changes!

Collapse
 
afifsohaili profile image
Afif Sohaili • Edited

Hi, I just googled for it, and I was mindblown. Definitely will opt for that instead. I didn't know. 😁

This is why I love the comments section!

Edit: I just reread your comment, and 🤔 do you mean the new for await of that came with ES2018?

Collapse
 
4umfreak profile image
Mark Voorberg • Edited

I did not mean for-await-of, I mean:

  for (var i = 0; i < asyncFunctions.length; i++) {
    var result = await asyncFunctions[i]();
    console.log(result);
  }
Enter fullscreen mode Exit fullscreen mode

Less code, less cognitive overhead!

jsfiddle.net/4umfreak/bkqcymuL/

Thread Thread
 
afifsohaili profile image
Afif Sohaili

Yeah, that's definitely a more readable approach. I have to be honest I haven't used for loops in a while so it didn't really occur to me.

Thread Thread
 
afifsohaili profile image
Afif Sohaili

@4umfreak updated the code to use plain ol' for-loops. Took me long enough.