Lodash _.reduceRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Like _.reduce, except it iterates over elements from right to left. Same iteratee signature and seed rules — only visit order changes. 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 _.reduceRight on a collection. Start with this line.

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

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

Library declarations
Lodash
_.reduceRight(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, last element is the seed

Return Value

Return ValueDescription
*Final accumulated value

Lodash Examples

Example 1 — Official: Flatten from the Right

Concat nested arrays starting at the last pair.

Lodash
var array = [[0, 1], [2, 3], [4, 5]];

_.reduceRight(array, function (flattened, other) {
  return flattened.concat(other);
}, []);
// → [4, 5, 2, 3, 0, 1]
Try It Yourself

How It Works

  1. Seed. Start with [].
  2. Last pair first. Concat [4, 5].
  3. Then middle. Append [2, 3].
  4. Then first. Append [0, 1] → final order ends with the left pair.

Example 2 — Same Iteratee, Opposite Direction

Compare _.reduce and _.reduceRight on the same concat fold.

Lodash
var array = [[0, 1], [2, 3], [4, 5]];
var join = function (a, b) { return a.concat(b); };

_.reduce(array, join, []);
// → [0, 1, 2, 3, 4, 5]

_.reduceRight(array, join, []);
// → [4, 5, 2, 3, 0, 1]
Try It Yourself

How It Works

  1. Same function. Both call concat with the same seed.
  2. reduce. Visits left → right → natural order.
  3. reduceRight. Visits right → left → reversed pair order.
  4. Lesson. Direction changes the result when combine order matters.

Example 3 — Subtraction (Order Matters)

Non-commutative math shows why direction is not optional.

Lodash
_.reduce([10, 3, 2], function (a, b) {
  return a - b;
});
// → 5    (10 − 3 − 2)

_.reduceRight([10, 3, 2], function (a, b) {
  return a - b;
});
// → -11  (2 − 3 − 10)
Try It Yourself

How It Works

  1. No seed. First/last element becomes the accumulator.
  2. reduce. Seed 10, then 10−3=7, then 7−2=5.
  3. reduceRight. Seed 2, then 2−3=−1, then −1−10=−11.
  4. Rule. For − / / / concat, pick the direction on purpose.

Example 4 — No Initial Accumulator

Without a seed, the last element is the starting accumulator.

Lodash
_.reduceRight([2, 3, 4], function (acc, n) {
  return acc * n;
});
// → 24   (seed was 4; then 4×3×2)
Try It Yourself

How It Works

  1. Auto-seed. Last value 4 starts the fold.
  2. Walk left. Multiply by 3, then by 2.
  3. Product. 4 × 3 × 2 = 24 — same as a left fold here because × is commutative.
  4. Caution. Empty array + no seed → undefined.

Example 5 — Empty Collection with Seed

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

Lodash
_.reduceRight([], function (flat, other) {
  return flat.concat(other);
}, []);
// → []
Try It Yourself

How It Works

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

Browser & Runtime Support

_.reduceRight 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+

_.reduceRight()

Available in [email protected] full builds and the lodash/reduceRight 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
_.reduceRight Lodash 4.x+

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

Frequently Asked Questions

_.reduceRight(collection, iteratee, [accumulator]) folds every element into one value, walking from right to left. Same iteratee signature as _.reduce — only the visit order changes.
When order matters: concatenation from the end, subtraction/division chains, or building strings where the last element should be processed first.
Conceptually similar for arrays, but reduceRight walks right-to-left without allocating a reversed copy. Prefer reduceRight when direction is the only difference.
The last element becomes the seed, and iteration continues leftward. Prefer an explicit seed — especially when the collection may be empty.
It does not change the source. Your iteratee may mutate the accumulator if you reuse and return the same reference.
Use import reduceRight from "lodash/reduceRight" or require("lodash/reduceRight") for tree-shaking. Full build: import _ from "lodash" then _.reduceRight.

Next: _.reject()

Keep the elements that fail a predicate — the opposite of filter.

_.reject() 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