
How to use it: pass in a predicate function that will be evaluated against each element of the array. When to use it: you need a subset of the original array. Let’s refactor some for-loops (or forEach implementations) into better code with these other methods. However forEach is arguably the least awesome of the array methods we have available to us in JavaScript. It is very similar to writing a for.of loop, but inline. It’s a great method as it allows us to bypass all the boilerplate of making a for-loop: no temporary index variable, no checking against the array length, no clunky arrayName code to access an element. For those who don’t know what forEach does, it effectively replaces a for-loop iterating over an array: const names = Ĭonst uppercaseNames = for (let i = 0 i uppercaseNames.push(name.toUppercase()))


The array method forEach is wonderfully useful, but I see it used in instances where other array methods are a better fit.

ForEach, Filter, Map, Reduce, Slice, Find In Javascript
