Skip to content

Instantly share code, notes, and snippets.

@otonielguajardo
Created October 13, 2021 00:07
Show Gist options
  • Save otonielguajardo/dd48207f376cfde678608b7b46346cd0 to your computer and use it in GitHub Desktop.
Save otonielguajardo/dd48207f376cfde678608b7b46346cd0 to your computer and use it in GitHub Desktop.
Use async await with a forEach loop
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