Lodash _.reduceRight() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.reduceRight(collection, iteratee, accumulator) mirrors reduce but walks backward.
  • Contrast outputs when operations depend on evaluation order.
  • How object visitation interacts with right folds.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.reduce() first—the iteratee contract is identical; only traversal direction changes.

  • You understand commutative versus order-sensitive combining operators.
  • You can open Try-it labs or run snippets locally.

Overview

_.reduceRight keeps Lodash iteratee ergonomics while honoring algorithms that naturally consume data from the tail—reverse polish vibes without reversing arrays manually.

Backward folds

Accumulator sees trailing elements first on arrays.

Same signature

Swap direction without rewriting callback plumbing.

Mind ordering

Addition might match reduce—but concatenation usually won’t.

Syntax

javascript
_.reduceRight(collection, iteratee, [accumulator])
  • collection: array or plain object Lodash can iterate.
  • iteratee: (accumulator, value, index|key, collection); invoked from last element backward.
  • accumulator (optional): initial fold state—prefer explicit values when empties occur.
  • Returns: final accumulator after visiting every element.
1

Push indexes onto an array tail-first

Compared with reduce, elements append in reverse visitation order.

javascript
import reduceRight from "lodash/reduceRight";

reduceRight([1, 2, 3], (acc, n) => [...acc, n], []);
// → [3, 2, 1]

// Versus reduce(...) → [1, 2, 3]
Try it Yourself
2

Concatenate strings from right to left

Sequential concatenation is not commutative—direction decides the final literal.

javascript
import reduceRight from "lodash/reduceRight";

reduceRight(["a", "b", "c"], (acc, ch) => acc + ch, "");
// → "cba"
Try it Yourself
3

Fold object values tail-first

Concatenate numeric coercions as strings—reverse visitation yields "321" rather than "123".

javascript
import reduceRight from "lodash/reduceRight";

reduceRight(
  { a: 1, b: 2, c: 3 },
  (acc, value) => acc + String(value),
  ""
);
// → "321"
Try it Yourself

📋 _.reduceRight vs reduce, native reduceRight

APITraversalBest when
_.reduceRight(collection, iteratee, acc)Tail → headAlgorithms needing trailing-first accumulation
_.reduce(collection, iteratee, acc)Head → tailDefault forward folds
Array.prototype.reduceRightTail → head (arrays only)Pure arrays without Lodash iteratee sugar

Pitfalls to avoid

Math

Looks commutative?

Addition/multiplication often hide direction—test with subtraction or string ops.

Perf

Spread chains

Spreading into new arrays each iteration is educational but allocations-heavy—mutate carefully when scaling.

Objects

Key expectations

Document expected enumeration—tie-break logic depends on engine-stable ordering.

❓ FAQ

No—it folds without allocating a reversed copy (conceptually mirrored traversal).
Yes—(accumulator, value, index|key, collection); only visitation schedule differs.
Whenever combining operations are not commutative or associative—subtraction, string prepend semantics, matrix folds.
Lodash walks enumerable entries predictably—mirror fixtures when parity with insertion-order intuition matters.
Same cautions as reduce—explicit seeds keep empty-collection bugs contained.

Summary

Did you know?

Use reduceRight when tail-first visitation defines correctness—string builders, subtract/divide chains, or prepend-heavy list constructions—not merely because data happens to look reversed.

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.

6 people found this page helpful