Skip to content

Instantly share code, notes, and snippets.

@carlelieser
Created January 27, 2021 05:49
Show Gist options
  • Save carlelieser/aa6cb7a80e935bf846adfea6068b4a17 to your computer and use it in GitHub Desktop.
Save carlelieser/aa6cb7a80e935bf846adfea6068b4a17 to your computer and use it in GitHub Desktop.
async forEach / typescript
Array.prototype.asyncForEach = async function asyncForEach(
fn: (item: any, index: number) => void,
index: number = 0
) {
await fn(this[index], index);
if (index + 1 === this.length) return;
await asyncForEach.call(this, fn, index + 1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment