DEV Community

dannohh
dannohh

Posted on

1

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)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay