reduce() - Aggregate Values in JavaScript

From the JavaScript Array Methods cheat sheet · Transformation Methods · verified Jul 2026

reduce() - Aggregate Values

Reduce array to single value using accumulator

javascript
// Sum all numbers
const sum = [1, 2, 3].reduce((acc, x) => acc + x, 0);
// 6

// Group by property
const grouped = items.reduce((acc, item) => {
  acc[item.category] = acc[item.category] || [];
  acc[item.category].push(item);
  return acc;
}, {});
🔴 Advanced - Powerful but complex method
💡 Can return any type: number, string, object, array
⚡ Use for sums, counts, grouping, flattening
⚠️ Always provide initial value to avoid errors
📌 Accumulator carries value between iterations

Continue with JavaScript Array Methods

Save the full cheat sheet or work through every related task.

More JavaScript tasks

Back to the full JavaScript Array Methods cheat sheet