You don’t need reduce.

reduce makes the reader replay your code in their head, and it fails quietly when one detail is off. Modern JavaScript has a named method for almost every job it gets used for.

const prices = [0.1, 0.2, 0.3]; With reduce: prices.reduce((sum, p) => sum + p, 0);// 0.6000000000000001Instead: Math.sumPrecise(prices);// 0.6
Math.sumPrecise adds without rounding at every step. Standard since ES2026.

Grouping items by a key

The accumulator has to be returned by hand on every step. Leave out return groups and the second item crashes with a TypeError.

With reduce
const byRole = users.reduce((groups, user) => {  (groups[user.role] ??= []).push(user);  return groups;}, {});
Instead
const byRole = Object.groupBy(users, (user) => user.role);

Object.groupBy, standard since ES2024. Use Map.groupBy when the keys aren’t strings.

Counting occurrences

A plain object inherits keys from Object.prototype, so counting the word “constructor” starts from a function instead of zero.

With reduce
const counts = words.reduce((acc, word) => {  acc[word] = (acc[word] || 0) + 1;  return acc;}, {});// counts.constructor: "function Object() { [native code] }1"
Instead
const counts = new Map();for (const word of words) {  counts.set(word, (counts.get(word) ?? 0) + 1);}

for…of and Map, standard since ES2015. A loop reads top to bottom, and nothing has to be handed back each time.

Looking items up by id

Spreading the accumulator copies every key it already holds on each step. For 10,000 users, that’s about 50 million copies to build one object.

With reduce
const byId = users.reduce(  (acc, user) => ({ ...acc, [user.id]: user }),  {},);
Instead
const byId = Object.fromEntries(  users.map((user) => [user.id, user]),);

Object.fromEntries, standard since ES2019. Pass the same pairs to new Map() when the keys aren’t strings.

Checking whether every item passes

The answer is settled at the first unpaid invoice, but reduce keeps calling back for every one after it. The intent hides inside ok &&.

With reduce
const allPaid = invoices.reduce(  (ok, invoice) => ok && invoice.paid,  true,);
Instead
const allPaid = invoices.every((invoice) => invoice.paid);

every and some, standard since ES5. Both stop at the first item that decides the answer.

Flattening nested arrays

concat builds a fresh array on every step, so the work grows with the square of the input.

With reduce
const tags = posts.reduce(  (all, post) => all.concat(post.tags),  [],);
Instead
const tags = posts.flatMap((post) => post.tags);

flatMap and flat, standard since ES2019.

Filtering and transforming in one pass

This shape exists to skip the extra array that .filter().map() creates. Iterator helpers skip it too, and every step keeps its name.

With reduce
const emails = users.reduce((acc, user) => {  if (user.active) acc.push(user.email);  return acc;}, []);
Instead
const emails = users  .values()  .filter((user) => user.active)  .map((user) => user.email)  .toArray();

Iterator helpers, standard since ES2025. Each user goes through filter and map before the next one starts.

Removing duplicates

includes scans the whole accumulator for every item, then the spread copies it all over again.

With reduce
const unique = ids.reduce(  (acc, id) => (acc.includes(id) ? acc : [...acc, id]),  [],);
Instead
const unique = [...new Set(ids)];

Set, standard since ES2015. To compare lists, Set has union, intersection and difference, standard since ES2025.

Finding the largest value

Without an initial value, reduce throws on an empty array. With one, you have to invent a number that can never win.

With reduce
const highest = scores.reduce(  (max, score) => (score > max ? score : max),);
Instead
const highest = Math.max(...scores);

Math.max, standard since ES1. An empty array gives -Infinity. Past roughly 100,000 items, spreading can hit the engine’s argument limit, so use a loop there.

Running async work in order

Forget await previous and every request starts at once. The responses are thrown away either way.

With reduce
await urls.reduce(async (previous, url) => {  await previous;  await fetch(url);}, Promise.resolve());
Instead
const responses = await Array.fromAsync(  urls,  (url) => fetch(url),);

Array.fromAsync, standard since ES2026. Each fetch finishes before the next one starts, and you keep the results.

Not on the list? Write the loop.

If no method name says what your callback does, a for…of loop will. It reads one line at a time, and break, continue and await work in it without tricks.

To keep reduce out of a codebase, turn on unicorn/no-array-reduce in ESLint.