Underscore.js _.reduceRight() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Collection

Definition

The right-associative version of _.reduce — same fold idea, but it walks the list from the last element to the first (official Underscore docs). Stable Collection helper — not deprecated.

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

Syntax

Call _.reduceRight. Start with this line.

Underscore
_.reduceRight(list, iteratee, [memo])
CallWhat it does
_.reduceRight(list, iteratee, [memo])Primary signature.
_.reduceRight(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.reduceRight(list, iteratee, [memo])

Parameters

ParameterDescription
listRequired. Collection to fold
iterateeRequired. (memo, value, index|key, list) → nextMemo
memoOptional. Starting accumulator (*recommended)
contextOptional. this for the iteratee

Return Value

Return ValueDescription
*The value returned by _.reduceRight().

Underscore.js Examples

Example 1 — Flatten From the Right

Concatenate pairs starting at the last chunk — the official docs pattern.

Underscore
var list = [[0, 1], [2, 3], [4, 5]];

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

How It Works

  1. Start empty. Memo is [].
  2. Last pair first. Concat [4, 5], then [2, 3], then [0, 1].
  3. Order flips. Chunks appear in reverse order vs left reduce.
  4. Same API. Only the walk direction changed.

Example 2 — String Concat Right-to-Left

Appending from the end reverses letter order.

Underscore
var letters = ["a", "b", "c", "d"];

_.reduceRight(letters, function (memo, letter) {
  return memo + letter;
}, "");
// → "dcba"
Try It Yourself

How It Works

  1. Seed "". Empty string starts the join.
  2. Meet d first. Then c, b, a.
  3. Result. "dcba" — reverse of left-to-right join.
  4. Non-commutative. Order of + changes the answer.

Example 3 — reduce vs reduceRight

Same list, same iteratee — direction alone changes the string.

Underscore
var words = ["a", "b", "c"];

_.reduce(words, function (m, w) { return m + w; }, "");
// → "abc"

_.reduceRight(words, function (m, w) { return m + w; }, "");
// → "cba"
Try It Yourself

How It Works

  1. Left fold. Sees a, then b, then c → "abc".
  2. Right fold. Sees c, then b, then a → "cba".
  3. Same callback. Only iteration order differs.
  4. Sums agree. Addition would match either way.

Example 4 — No Initial Memo

Omit memo and the last element seeds the accumulator.

Underscore
var letters = ["a", "b", "c"];

_.reduceRight(letters, function (memo, letter) {
  return memo + letter;
});
// → "cba"  (starts with memo="c", then +"b", +"a")
Try It Yourself

How It Works

  1. Seed from end. Last value "c" becomes memo.
  2. Move left. Iteratee runs on "b", then "a".
  3. Result. "cba" without an empty-string seed.
  4. Caution. Empty lists still need an explicit memo.

Browser & Runtime Support

_.reduceRight ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.reduceRight()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded. Alias foldr included.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]). Native alternative: Array.prototype.reduceRight on real arrays.

Frequently Asked Questions

_.reduceRight(list, iteratee, [memo], [context]) is the right-associative version of _.reduce. It folds a collection into one value, processing from the last element to the first.
No. foldr is an alias of reduceRight — same function.
Both fold into one value. _.reduce goes left-to-right; _.reduceRight goes right-to-left. Order matters for concat, subtraction, and similar ops.
The last element becomes the starting memo, and iteration continues toward the first element.
When combination order matters and you need to start from the end — for example right-to-left concat. Prefer _.reduce for ordinary left-to-right totals.
The official docs note foldr is less useful in JavaScript than in languages with lazy evaluation. Reach for it when direction truly matters.

Next: _.find()

Return the first element that passes a predicate test.

_.find() →

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