Skip to content

Instantly share code, notes, and snippets.

View murtuzaalisurti's full-sized avatar
:octocat:
breaking and fixing code

Murtuzaali Surti murtuzaalisurti

:octocat:
breaking and fixing code
View GitHub Profile

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

@murtuzaalisurti
murtuzaalisurti / findStyles.js
Created December 4, 2022 13:02 — forked from macbookandrew/findStyles.js
List unique CSS properties for all DOM elements
/**
* List unique CSS properties for all DOM elements
* Initially created to list unique font stacks on a page
* @see {@link http://stackoverflow.com/a/35022690/ Inspired by this StackOverflow answer}
*
* @see {@link https://gist.github.com/macbookandrew/f33dbbc0aa582d0515919dc5fb95c00a/ URL for this file}
*
* @author AndrewRMinion Design (https://andrewrminion.com)
* @version 1.1
*