Lodash _.reduce() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Reduces a collection to a single accumulated value by running each element through an iteratee. If no accumulator is given, the first element is used as the initial value. Part of Lodash 4.x Collection (since 0.1.0).

Pass the required arguments shown below. Lodash Collection helpers usually return a new value — check whether the source is mutated.

Syntax

Call _.reduce on a collection. Start with this line.

Lodash
_.reduce(collection, [iteratee=_.identity], [accumulator])
CallWhat it does
_.reduce(collection, [iteratee=_.identity], [accumulator])Primary signature.
_.reduce(collection)Call with a collection argument.

Prefer import reduce from "lodash/reduce" when you want a smaller bundle.

Library declarations
Lodash
_.reduce(collection, [iteratee=_.identity], [accumulator])

Parameters

ParameterDescription
collectionRequired. Array or object to fold
iterateeOptional. (acc, value, index|key, collection); default identity
accumulatorOptional. Initial value; if omitted, first element is the seed

Return Value

Return ValueDescription
*Final accumulated value

Lodash Examples

Example 1 — Official: Sum with Seed

Start at 0 and add each number.

Lodash
_.reduce([1, 2], function (sum, n) {
  return sum + n;
}, 0);
// → 3
Try It Yourself

How It Works

  1. Seed. Accumulator starts at 0.
  2. First value. 0 + 1 → 1.
  3. Second value. 1 + 2 → 3.
  4. Done. Final accumulator is the return value.

Example 2 — Official: Fold a Plain Object

Group object keys by their values into a new map.

Lodash
_.reduce({ a: 1, b: 2, c: 1 }, function (result, value, key) {
  (result[value] || (result[value] = [])).push(key);
  return result;
}, {});
// → { "1": ["a", "c"], "2": ["b"] }
Try It Yourself

How It Works

  1. Seed. Start with an empty object {}.
  2. Keys as third arg. Lodash passes key ("a", "b", "c").
  3. Bucket by value. Push each key into result[value].
  4. Return result. Always return the accumulator so the next step keeps it.

Example 3 — Product with Seed 1

Multiply numbers; seed must be 1, not 0.

Lodash
_.reduce([2, 3, 4], function (acc, n) {
  return acc * n;
}, 1);
// → 24
Try It Yourself

How It Works

  1. Seed 1. Multiplying by 0 would wipe the product.
  2. Steps. 1×2 → 2, then 2×3 → 6, then 6×4 → 24.
  3. Rule. Match the seed to the operation (sum→0, product→1).
  4. Safe empty. _.reduce([], fn, 1) still returns 1.

Example 4 — No Initial Accumulator

When the seed is omitted, the first element becomes the accumulator.

Lodash
_.reduce([10, 20, 30], function (sum, n) {
  return sum + n;
});
// → 60   (seed was 10; then +20 +30)
Try It Yourself

How It Works

  1. Auto-seed. 10 is taken as the starting accumulator.
  2. Iterate from index 1. Next values are 20 and 30.
  3. Result. 10 + 20 + 30 = 60 — same as seeding with 0 here.
  4. Caution. On an empty array with no seed, the result is undefined.

Example 5 — Empty Collection with Seed

With a seed, an empty collection returns that seed safely.

Lodash
_.reduce([], function (sum, n) {
  return sum + n;
}, 0);
// → 0
Try It Yourself

How It Works

  1. No elements. The iteratee never runs.
  2. Seed wins. Lodash returns the accumulator 0.
  3. Without seed. _.reduce([], fn) → undefined.
  4. Habit. Always pass a seed when empty input is possible.

Browser & Runtime Support

_.reduce is a Lodash 4.x Collection helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.reduce()

Available in [email protected] full builds and the lodash/reduce modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.reduce Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import reduce from "lodash/reduce" for smaller builds. Not a native browser API — load Lodash first. For arrays-only, native Array.prototype.reduce is also fine.

Frequently Asked Questions

_.reduce(collection, iteratee, [accumulator]) folds every element into one accumulated value. Each step receives the previous result plus the next value.
For arrays, Lodash uses the first element as the seed and starts iterating from the second. Prefer an explicit seed — especially when the collection may be empty.
It does not change the source collection. Your iteratee may mutate the accumulator object if you reuse and return the same reference.
_.reduce walks left-to-right; _.reduceRight walks right-to-left. Order matters for non-commutative operations like subtraction or string building.
Yes. Lodash iterates enumerable values and passes the key as the third iteratee argument.
Use import reduce from "lodash/reduce" or require("lodash/reduce") for tree-shaking. Full build: import _ from "lodash" then _.reduce.

Next: _.reduceRight()

Same fold idea, walking the collection from right to left.

_.reduceRight() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful