Created
January 27, 2021 05:49
-
-
Save carlelieser/aa6cb7a80e935bf846adfea6068b4a17 to your computer and use it in GitHub Desktop.
async forEach / typescript
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
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