đź‘‹ Hey Devs!
If you're learning JavaScript, chances are you've come across the trio: map(), filter(), and reduce().
These array methods are powerful but can be confusing at first. In this post, I’ll break them down with clean examples you can use in your own code.
🚀 1. map() – Transform Data
const prices = [10, 20, 30];
const taxIncluded = prices.map(price => price * 1.18);
console.log(taxIncluded); // [11.8, 23.6, 35.4]
📌 Use it when you need to convert or modify array items.
🔍 2. filter() – Keep What You Need
const scores = [45, 67, 89, 34];
const passing = scores.filter(score => score >= 60);
console.log(passing); // [67, 89]
📌 Use it when you want to exclude some data.
🧮 3. reduce() – Crunch Everything
const cart = [100, 200, 50];
const total = cart.reduce((acc, curr) => acc + curr, 0);
console.log(total); // 350
📌 Use it to sum, count, or combine data.
đź’ˇ Summary
These three methods are essential for writing clean, functional JavaScript. And once you get comfortable with them, you'll reach for them in almost every project.
đź“– Check out my full article with visual explanation and code breakdown:
👉 https://webcodingwithankur.blogspot.com/2025/06/javascript-map-filter-reduce-explained.html
Top comments (0)