DEV Community

dannohh
dannohh

Posted on

filter() and map() vs. forEach()

What are some of the advantages of using map() and filter() vs. using forEach() methods?

Firstly, the forEach() array method always returns a value of undefined. This might be good for some scenarios, but not all. It also mutates our original array, discarding the return values.

To Be Clear~

forEach() MUTATES the current array!

VS. map() and filter()

map() and filter() methods both return new arrays that we can work with, without affecting the original array! Sweet! New Toys 👍 🎅

Top comments (0)