I saw many posts comparing .forEach() and .map(), but I have never seen a situation where we are faced with a problem of choice between these 2 APIs.
Even if they both iterate through elements in an array, they stays totally different.
- The map() method creates a new array.
- The forEach() method executes a provided function once for each array element.
Top comments (1)
People are not comfortable with functional programming I think. Both functions browse the array so new devs use the two indistinctively. You appear to grasp the difference between the two so good for you. 😀