JavaScript Array Methods You Actually Use: map, filter, reduce and More
A practical guide to the JavaScript array methods that matter, map, filter, reduce, find, some and every, with clear examples of when to use each.
- →map transforms every item into a new array of the same length.
- →filter keeps only items that pass a test, returning a shorter array.
- →reduce boils an array down to a single value (a sum, an object, anything).
- →find returns the first matching item; some and every return booleans.
- →These methods don't mutate the original array, they return new values, which keeps code predictable.
Modern JavaScript is written with array methods, not for loops. Learn a handful, map, filter, reduce, find, some, every, and you'll write cleaner code that reads like what it does. Here's how to use each one, with the mental model for picking the right one.
map: transform every item
map takes an array and returns a new array of the same length, with each item transformed by your function. Use it whenever you want to turn one list into another.
const prices = [10, 20, 30];
const withTax = prices.map((p) => p * 1.2);
// [12, 24, 36]filter: keep what matches
filter returns a new array containing only the items that pass a test. The result is the same length or shorter, never transformed, just filtered.
const nums = [1, 2, 3, 4, 5, 6];
const evens = nums.filter((n) => n % 2 === 0);
// [2, 4, 6]map vs filter: map always returns the same number of items (transformed); filter returns a subset (unchanged). If you're changing items, map. If you're removing items, filter.
reduce: boil down to one value
reduce is the most powerful and most feared. It runs through the array accumulating a single result, a sum, a max, an object, anything. You give it a reducer function and a starting value.
const nums = [1, 2, 3, 4];
const total = nums.reduce((sum, n) => sum + n, 0);
// 10
// build an object: count occurrences
const words = ["a", "b", "a", "c", "b", "a"];
const counts = words.reduce((acc, w) => {
acc[w] = (acc[w] || 0) + 1;
return acc;
}, {});
// { a: 3, b: 2, c: 1 }find, some and every: search and test
- •find returns the first item that matches, or undefined. Use it to grab one thing.
- •some returns true if at least one item passes the test.
- •every returns true only if all items pass the test.
const users = [{ id: 1, active: true }, { id: 2, active: false }];
users.find((u) => u.id === 2); // { id: 2, active: false }
users.some((u) => u.active); // true
users.every((u) => u.active); // falseChaining methods
Because map and filter return arrays, you can chain them into a readable pipeline. This reads top to bottom like a description of the transformation.
const orders = [
{ total: 50, paid: true }, { total: 120, paid: false }, { total: 200, paid: true },
];
const revenue = orders
.filter((o) => o.paid)
.map((o) => o.total)
.reduce((sum, t) => sum + t, 0);
// 250The pattern to remember: filter to narrow, map to transform, reduce to summarize. Most data work is some combination of those three.
They don't mutate the original
A key reason to prefer these methods: map, filter and reduce return new arrays or values and leave the original untouched. That predictability makes your code easier to reason about, especially in React where mutating state directly causes bugs.
The short version
Use map to transform every item, filter to keep matching items, and reduce to collapse an array into one value. Use find for the first match, and some/every for boolean tests. Chain them into readable pipelines, and rely on the fact that they don't mutate the original array.
Frequently asked questions
What is the difference between map and filter in JavaScript?+
map transforms every item and returns a new array of the same length. filter tests each item and returns a new array containing only the ones that pass, so it's the same length or shorter. Use map to change items and filter to remove them.
What does reduce do in JavaScript?+
reduce runs a function across an array, accumulating a single result such as a sum, a maximum, or an object. You provide a reducer function and a starting value; each iteration returns the new accumulated value, and the final value is the result.
When should I use find instead of filter?+
Use find when you want the single first item that matches a condition, it returns that item or undefined. Use filter when you want all matching items as an array. find stops at the first match, so it's more efficient when you only need one.
Do JavaScript array methods change the original array?+
map, filter and reduce do not mutate the original array; they return new arrays or values. This makes them safe and predictable, which is why they're preferred in React, where directly mutating state causes bugs. (Methods like sort and splice do mutate, so copy first if needed.)
What's the difference between some and every?+
some returns true if at least one item in the array passes the test function. every returns true only if all items pass. Both stop early once the answer is known, some at the first pass, every at the first failure.
I build fast, SEO-ready sites and rank them on Google and AI search.