Skip to content

Instantly share code, notes, and snippets.

@vovk1805
Last active July 23, 2021 16:22
Show Gist options
  • Save vovk1805/74a0183b12fd449b31c4b4aedbba674b to your computer and use it in GitHub Desktop.
Save vovk1805/74a0183b12fd449b31c4b4aedbba674b to your computer and use it in GitHub Desktop.
Async forEach JS
const promise = new Promise((res) => res('lol'));
const arr = [1, 2, 3, 4, 5];
const result = [];
arr.forEach(async (el) => {
const res = await promise;
if (res === 'lol') {
result.push(el);
}
});
// тут би мав бути масив з числами
console.log('result ↓↓↓↓↓↓↓↓↓↓↓↓↓');
console.dir(result, { depth: 10000, colors: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment