Created
October 13, 2021 00:07
-
-
Save otonielguajardo/dd48207f376cfde678608b7b46346cd0 to your computer and use it in GitHub Desktop.
Use async await with a forEach loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const asyncForEach = async function (array: Array<any>, callback: any) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
}; | |
// await asyncForEach(collection, async (item) => { await doSomething(item); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment