Lodash _.forInRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Like _.forIn, but iterates properties of object in the opposite order. Visits own and inherited enumerable string keys. Part of Lodash Object since 2.0.0 (stable — not deprecated).

Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.

Syntax

Call _.forInRight. Start with this line.

Lodash
_.forInRight(object, [iteratee])
CallWhat it does
_.forInRight(object, [iteratee])Primary signature.
_.forInRight(object)Work with an object’s keys, values, or paths.

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

Library declarations
Lodash
_.forInRight(object, [iteratee])

Parameters

ParameterDescription
objectRequired. The object to iterate over
iterateeOptional. Invoked per key; default _.identity

Return Value

Return ValueDescription
*The original object

Lodash Examples

Example 1 — Official: Reverse Key Order

Own and inherited keys are visited opposite to _.forIn.

Lodash
function Foo() {
  this.a = 1;
  this.b = 2;
}

Foo.prototype.c = 3;

_.forInRight(new Foo, function(value, key) {
  console.log(key);
});
// → Logs 'c', 'b', then 'a'
//    (assuming _.forIn logs 'a', 'b', then 'c')
Try It Yourself

How It Works

  1. Instance. Own keys a and b; prototype key c.
  2. forIn order. Typically a → b → c.
  3. forInRight. Walks that sequence backward.
  4. Result. Logs c, then b, then a.

Example 2 — Side-by-Side With _.forIn

Same object; only the direction changes.

Lodash
function Foo() {
  this.a = 1;
  this.b = 2;
}
Foo.prototype.c = 3;

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

_.forIn(new Foo(), function (v, k) { left.push(k); });
_.forInRight(new Foo(), function (v, k) { right.push(k); });

// left  → ["a", "b", "c"]  (typical)
// right → ["c", "b", "a"]
Try It Yourself

How It Works

  1. Collect keys. Push each key into an array.
  2. Forward. forIn fills left-to-right order.
  3. Reverse. forInRight fills the opposite sequence.
  4. Same set. Both include the inherited c.

Example 3 — Iterate Values Too

The iteratee receives value and key on every step.

Lodash
var obj = { a: 1, b: 2, c: 3 };
var pairs = [];

_.forInRight(obj, function (value, key) {
  pairs.push(key + "=" + value);
});

// pairs → ["c=3", "b=2", "a=1"]
Try It Yourself

How It Works

  1. Plain object. Three own enumerable keys.
  2. Iteratee. Builds key=value strings.
  3. Order. Starts at the last key (c).
  4. Use. Side effects, logging, or collecting results yourself.

Example 4 — Early Exit With false

Return false to stop before every key is visited.

Lodash
var obj = { a: 1, b: 2, c: 3 };
var seen = [];

_.forInRight(obj, function (value, key) {
  seen.push(key);
  if (key === 'b') {
    return false;
  }
});

// seen → ["c", "b"]  (stops before "a")
Try It Yourself

How It Works

  1. Start. First visit is c.
  2. Next. Visit b and return false.
  3. Stop. a is never visited.
  4. Note. Only an explicit false breaks — other falsy returns do not.

Example 5 — vs _.forOwnRight

Inherited keys appear in forInRight, not in forOwnRight.

Lodash
function Foo() {
  this.a = 1;
  this.b = 2;
}
Foo.prototype.c = 3;

var inRight = [];
var ownRight = [];

_.forInRight(new Foo(), function (v, k) { inRight.push(k); });
_.forOwnRight(new Foo(), function (v, k) { ownRight.push(k); });

// inRight  → ["c", "b", "a"]
// ownRight → ["b", "a"]
Try It Yourself

How It Works

  1. forInRight. Includes prototype key c.
  2. forOwnRight. Own keys only → b, a.
  3. Both reverse. Direction is reversed relative to their forward counterparts.
  4. Choose. Use forOwnRight when inherited keys must be ignored.

Browser & Runtime Support

_.forInRight is a Lodash Object helper (available since 2.0.0, stable in 4.x). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 2.0.0+

_.forInRight()

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

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import forInRight from "lodash/forInRight" for smaller builds. Use _.forOwnRight when inherited keys must be skipped.

Frequently Asked Questions

_.forInRight(object, iteratee) iterates over an object's own and inherited enumerable string-keyed properties in the opposite order of _.forIn. It returns the original object.
The iteratee is invoked with (value, key, object).
Yes. Explicitly return false from the iteratee to exit iteration early.
Same key coverage (own + inherited). Opposite walk order.
_.forInRight also visits inherited enumerable keys. _.forOwnRight visits own keys only, also in reverse.
Use import forInRight from "lodash/forInRight" or require("lodash/forInRight"). Full build: import _ from "lodash" then _.forInRight.

Next: _.forOwn()

Iterate an object's own enumerable string keys (no prototype walk).

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