Looping over Arrays: for vs. for-in vs. .forEach() vs. for-of
I’ve always wondered about for and for-in and foreach and for-of. Through my own trial and error, my perception has become:
foris old school, what I learned in computer science 101forEachis what I’ll use most of the time, except when doing async stuff becauseawaitdoesn’t work inside itfor-inI use for async—or wait, should that befor-of? Meh, I’ll just useawait Promise.all.
The lazy person in me finally gets to understand all the fors. Now we’ll just see if I can remember it.