Lodash _.forEachRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Collection

Definition

Like _.forEach, but iterates right to left. On arrays it starts at the last index. Return false to stop early. Alias: _.eachRight. Part of Lodash 4.x Collection (since 2.0.0).

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

Syntax

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

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

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

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

Parameters

ParameterDescription
collectionRequired. Array or object to iterate
iterateeOptional. Called per element; default _.identity

Return Value

Return ValueDescription
*The original collection

Lodash Examples

Example 1 — Official: Log Right to Left

Visit [1, 2] starting at the last element.

Lodash
var logged = [];

_.forEachRight([1, 2], function (value) {
  logged.push(value);
});

// logged → [2, 1]
Try It Yourself

How It Works

  1. Start at end. First visit is index 1 → value 2.
  2. Then left. Next visit is index 0 → value 1.
  3. Record. Push order mirrors visit order.
  4. Return. _.forEachRight returns the original array.

Example 2 — Index Order From the Tail

Collect indexes to prove the reverse walk.

Lodash
var seen = [];

_.forEachRight(["a", "b", "c"], function (_value, index) {
  seen.push(index);
});

// seen → [2, 1, 0]
Try It Yourself

How It Works

  1. Length 3. Last index is 2.
  2. Countdown. Indexes visited: 2 → 1 → 0.
  3. Values ignored. Callback only records the index argument.
  4. Use. Handy when debugging “newest first” UI stacks.

Example 3 — Build a String Tail-First

Concatenation order follows reverse visits.

Lodash
var acc = "";

_.forEachRight([10, 20, 30], function (n) {
  acc += String(n);
});

// acc → "302010"
Try It Yourself

How It Works

  1. First. Append 30.
  2. Next. Append 20 → "3020".
  3. Last. Append 10 → "302010".
  4. vs forEach. Left-to-right would yield "102030".

Example 4 — Early Exit From the Right

Return false after two visits — remaining left items are skipped.

Lodash
var hits = [];

_.forEachRight([10, 5, 20], function (value) {
  hits.push(value);
  if (hits.length === 2) {
    return false;
  }
});

// hits → [20, 5]   // 10 never visited
Try It Yourself

How It Works

  1. Start. Visit 20 first → hits = [20].
  2. Next. Visit 5 → length becomes 2.
  3. Stop. Return false — do not visit 10.
  4. Same rule. Only boolean false breaks (like _.forEach).

Example 5 — _.forEach vs _.forEachRight

Same array, opposite visit order.

Lodash
var left = [];
var right = [];

_.forEach([1, 2, 3], function (n) { left.push(n); });
_.forEachRight([1, 2, 3], function (n) { right.push(n); });

// left  → [1, 2, 3]
// right → [3, 2, 1]
Try It Yourself

How It Works

  1. forEach. Starts at 1 → natural order.
  2. forEachRight. Starts at 3 → reverse order.
  3. No copy. Neither method reverses the source array.
  4. Pick. Use Right for “newest / last first” effects.

Browser & Runtime Support

_.forEachRight is a Lodash 4.x Collection helper (alias _.eachRight, since 2.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native Array.forEach has no built-in right-to-left mode.

✓ Stable · Lodash 4.x

_.forEachRight()

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

Bottom line: Safe for production once Lodash is loaded. Prefer import forEachRight from "lodash/forEachRight" for smaller builds. Use when reverse visit order (or early exit from the end) matters.

Frequently Asked Questions

_.forEachRight(collection, iteratee) calls iteratee for each element from right to left. On arrays it starts at the last index. It returns the original collection.
Same API and early-exit rules — only the visit order changes. forEach goes left-to-right; forEachRight goes right-to-left.
Return boolean false from the iteratee. Lodash stops visiting further elements (toward the start).
_.eachRight is an alias of _.forEachRight — same behavior.
forEachRight avoids allocating a reversed copy and keeps Lodash iteratee behavior consistent.
Object key order follows Lodash enumeration. Prefer arrays when reverse order must be predictable.

Next: _.groupBy()

Bucket collection values into groups by a key or iteratee.

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

8 people found this page helpful