For-each over an array in JavaScript

TL;DR Your best bets are usually a for-of loop (ES2015+ only; spec | MDN) – simple and async-friendly forEach (ES5+ only; spec | MDN) (or its relatives some and such) – not async-friendly (but see details) a simple old-fashioned for loop – async-friendly (rarely) for-in with safeguards – async-friendly Some quick “don’t”s: Don’t use for-in … Read more

What’s the difference between “{}” and “[]” while declaring a JavaScript array?

Nobody seems to be explaining the difference between an array and an object. [] is declaring an array. {} is declaring an object. An array has all the features of an object with additional features (you can think of an array like a sub-class of an object) where additional methods and capabilities are added in … Read more