Skip to content

Instantly share code, notes, and snippets.

@wodCZ
Forked from Atinux/async-foreach.js
Last active November 21, 2019 13:36
Show Gist options
  • Save wodCZ/386a79b091a9fb6cacb24baf3873cb07 to your computer and use it in GitHub Desktop.
Save wodCZ/386a79b091a9fb6cacb24baf3873cb07 to your computer and use it in GitHub Desktop.
JavaScript: async/await with forEach()
export async function asyncForEach<T>(array: T[], callback: (item: T, index: number, allItems: T[]) => void) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment