Skip to content

Instantly share code, notes, and snippets.

@joshuaaguilar20
Created August 6, 2021 02:44
Show Gist options
  • Save joshuaaguilar20/0cdbdeaaa63887db17aae2172ed22508 to your computer and use it in GitHub Desktop.
Save joshuaaguilar20/0cdbdeaaa63887db17aae2172ed22508 to your computer and use it in GitHub Desktop.
Proper Async await foreach loop
  1. foreach loop does not work for async and always returns undefined.
  2. for of loop must be used.
//PROPER ASYNC AWAIT FOREACH LOOP


const arr = [1,2,3,4,5,6,7,8,9,10]

for (const [index, value] of arr.entries()) {
   await /* YOUR FUNCTION HERE */

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment