JavaScript map, filter and reduce with Examples
Transform, select and summarize array data using common built-in methods.
map: transform each item
const prices = [100, 200, 300];const withTax = prices.map(price => price * 1.18);
filter: keep matching items
const activeUsers = users.filter(user => user.active);reduce: accumulate a result
const total = [10, 20, 30].reduce((sum, value) => sum + value, 0);find and some
const admin = users.find(user => user.role === 'admin');const hasInactive = users.some(user => !user.active);
find returns the first matching item or undefined. some returns a boolean.
Quick reference
| Method | Purpose | Returns |
| map | Transform items | New array |
| filter | Keep matches | New array |
| reduce | Accumulate | Any value |
| find | First match | Item or undefined |
| some | Any match? | Boolean |
Keep learning
Try the concepts in a small project and verify version-specific details with official documentation.
More JavaScript resources