21/06/2025
Should I use forEach(), map() or filter()🤔?
This used to confuse me a lot when I was learning JavaScript.
Honestly, I mixed them up all the time😁.
But here’s what finally helped me understand them in real life terms:
✅ forEach() means you just do something with every item.
You're not changing or keeping anything.
You're just going through and maybe logging, alerting, or whatever.
Like calling each friend to say "hi." No one gets removed or changed.
✅ map() is for turning each item into something new.
You get a new list with the same number of items, just transformed.
It’s like turning raw ingredients into a cooked meal.
✅ filter() means you only keep items that meet a condition.
It’s like doing laundry and keeping only the clean clothes in the basket.
✅ sort() means you rearrange the items.
Nothing is added or removed, just reordered.
Like lining your books from shortest to tallest or sorting names alphabetically.
✅ find() means you grab the first item that matches a condition.
You’re not collecting a group, just finding one.
It's like picking out the first red shirt from a pile.
Once I started thinking of them like this, everything made more sense. I use them with intention now, and arrays feel less confusing.
If this helps, save it. I wish someone had explained it to me like this earlier 🙌
Simple Verse Zone