JavaScript Array Methods in 2026: The Complete Practical Guide
Master JavaScript array methods: map, filter, reduce, find, some, every, flat, and more. Includes real-world examples, performance tips, and when to use each method.
JavaScript Array Methods in 2026: The Complete Practical Guide
The Big Four
| Method | Returns | Mutates Original |
|---|---|---|
map() | New array (same length) | โ No |
filter() | New array (subset) | โ No |
reduce() | Single value | โ No |
find() | First match | โ No |
map() โ Transform Every Item
const users = [{name: 'Alice', age: 30}, {name: 'Bob', age: 25}];
// โ Old way
const names = [];
for (const user of users) {
names.push(user.name);
}
// โ
map
const names = users.map(u => u.name); // ['Alice', 'Bob']
// Transform to different shape
const cards = users.map(u => ({
title: u.name,
subtitle: `${u.age} years old`,
id: u.id
}));
filter() โ Keep Only What Matches
const products = [
{ name: 'Keyboard', price: 150, inStock: true },
{ name: 'Mouse', price: 80, inStock: false },
{ name: 'Monitor', price: 500, inStock: true },
];
// Filter by condition
const available = products.filter(p => p.inStock); // Keyboard, Monitor
const expensive = products.filter(p => p.price > 100); // Keyboard, Monitor
// Chain with map
const availableNames = products
.filter(p => p.inStock)
.map(p => p.name); // ['Keyboard', 'Monitor']
reduce() โ Accumulate to One Value
const orders = [
{ id: 1, total: 100, status: 'completed' },
{ id: 2, total: 250, status: 'completed' },
{ id: 3, total: 50, status: 'cancelled' },
];
// โ Imperative way
let total = 0;
for (const order of orders) {
if (order.status === 'completed') total += order.total;
}
// โ
reduce
const total = orders
.filter(o => o.status === 'completed')
.reduce((sum, o) => sum + o.total, 0); // 350
// Group by field
const byStatus = orders.reduce((groups, order) => {
groups[order.status] = groups[order.status] || [];
groups[order.status].push(order);
return groups;
}, {});
find() / findIndex() โ Get First Match
const users = [
{ id: 1, role: 'admin' },
{ id: 2, role: 'user' },
{ id: 3, role: 'user' },
];
// find: returns the element
const admin = users.find(u => u.role === 'admin'); // { id: 1, role: 'admin' }
// findIndex: returns the index
const adminIndex = users.findIndex(u => u.role === 'admin'); // 0
// NOT find: returns boolean
const hasAdmin = users.some(u => u.role === 'admin'); // true
some() / every() โ Boolean Aggregates
const users = [
{ name: 'Alice', verified: true },
{ name: 'Bob', verified: false },
{ name: 'Carol', verified: true },
];
// some: at least one matches
const hasUnverified = users.some(u => !u.verified); // true
// every: all must match
const allVerified = users.every(u => u.verified); // false
flat() / flatMap() โ Handle Nested Arrays
const nested = [[1, 2], [3, 4], [5, 6]];
// flat: flatten one level
const flat = nested.flat(); // [1, 2, 3, 4, 5, 6]
// flatMap: map then flatten
const doubled = nested.flatMap(arr => arr.map(n => n * 2)); // [2, 4, 6, 8, 10, 12]
Performance Tips
// โ Don't use map + filter when filter alone is enough
const result = array.map(x => transform(x)).filter(x => x !== null);
// โ
Combine with flatMap or use filter first
const result = array
.map(x => (condition(x) ? transform(x) : null))
.filter(x => x !== null); // still not ideal
// โ
Better: reduce in one pass
const result = array.reduce((acc, x) => {
if (condition(x)) acc.push(transform(x));
return acc;
}, []);
Method Chaining
const data = [
{ category: 'electronics', price: 100, rating: 4.5 },
{ category: 'electronics', price: 200, rating: 4.8 },
{ category: 'books', price: 20, rating: 4.2 },
];
// Chain: filter โ sort โ map
const topElectronics = data
.filter(d => d.category === 'electronics' && d.rating >= 4.5)
.sort((a, b) => b.rating - a.rating)
.map(d => ({ name: d.category, score: d.rating })); Free Newsletter
Level Up Your Dev Workflow
Get new tools, guides, and productivity tips delivered to your inbox.
Plus: grab the free Developer Productivity Checklist when you subscribe.
Found this guide useful? Check out our free developer tools.
Affiliate disclosure: Some links below are affiliate links โ we may earn a small commission at no extra cost to you. Learn more.
Recommended Tools & Resources
DigitalOcean
$200 credit for new users. Simple, affordable cloud hosting for developers.
GitHub Student Pack
Free access to 100+ developer tools. Perfect for students and new devs.
Vercel
Deploy frontend apps instantly. Free tier is generous for side projects.
DevPlaybook Products
Boilerplates, scripts & AI toolkits to 10x your dev workflow.