map() transforms each element and returns a new array of the same length, filter() returns elements that pass a test, and reduce() accumulates array elements into a single value.
These are three fundamental array methods for functional programming in JavaScript:
map()
filter()
reduce()
const numbers = [1, 2, 3, 4, 5];
// Double each number
const doubled = numbers.map(num => num * 2);
console.log(doubled); // [2, 4, 6, 8, 10]
// Extract property from objects
const users = [
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 }
];
const names = users.map(user => user.name);
console.log(names); // ['Alice', 'Bob']Chaining map, filter, and reduce for ETL (Extract, Transform, Load) operations on datasets
Filter in-stock products, map to extract prices, and reduce to calculate cart totals
Filter arrays based on user input in real-time for search suggestions
Using reduce to sum metrics, count occurrences, and group data by categories
Build a cart that uses reduce for totals, map for formatting, and filter for applying discounts
Fetch JSON data, transform with map, filter by criteria, and reduce for statistics