Lodash _.forOwnRight() method

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

What you’ll learn

  • How _.forOwnRight(object, iteratee) walks an object’s own enumerable string keys from last to first.
  • The iteratee signature (value, key, object) and the early-exit pattern (return false).
  • Why reverse direction is safer when you intend to delete keys mid-loop.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.forOwn() first if the iteratee shape is new; _.forOwnRight only changes the scan direction.

  • Own properties: only keys assigned directly to the object are visited—same set as Object.keys().
  • Iteration order: reverse of _.forOwn. Symbol keys and non-enumerable properties are skipped.
  • Mutation discipline: deleting the current key while walking in reverse never shifts unvisited positions—great for inline cleanup.

Overview

_.forOwnRight invokes the iteratee for each own enumerable string key—but from the last key to the first. The original object is returned, which makes this a side-effect helper for last-wins overrides, cleanup, or reverse logging.

Reverse scan

Same key coverage as _.forOwn, walked from last to first.

Own keys only

Inherited prototype keys are skipped automatically—no hasOwnProperty boilerplate.

Early exit

Return false from the iteratee to stop before every key is visited.

Syntax

javascript
_.forOwnRight(object, [iteratee=_.identity])
  • object: object whose own enumerable string keys are iterated in reverse.
  • iteratee: function invoked with (value, key, object).
  • Early exit: return false to stop iteration.
  • Returns: the original object.
1

Iterate own keys in reverse order

For a plain object, _.forOwnRight visits each own key once, starting from the last-inserted one.

javascript
import forOwnRight from "lodash/forOwnRight";

const sampleObject = { a: 1, b: 2, c: 3 };

const lines = [];
forOwnRight(sampleObject, (value, key) => {
  lines.push(`${key}: ${value}`);
});

// lines -> ["c: 3", "b: 2", "a: 1"]
Try it Yourself
2

Inherited keys are still skipped

The Right suffix only flips iteration order. _.forOwnRight still ignores enumerable prototype keys; _.forInRight visits them.

javascript
import forOwnRight from "lodash/forOwnRight";
import forInRight  from "lodash/forInRight";

function Animal(name) {
  this.name = name;
}

Animal.prototype.sound = "Unknown";

const cat = new Animal("Whiskers");

const ownRightKeys = [];
forOwnRight(cat, (value, key) => ownRightKeys.push(key));

const inRightKeys = [];
forInRight(cat, (value, key) => inRightKeys.push(key));

// ownRightKeys -> ["name"]
// inRightKeys  -> ["sound", "name"]
Try it Yourself
3

In-place cleanup: drop null / undefined

Reverse iteration is a natural fit when you delete the current key—you never disturb a slot you still need to visit.

javascript
import forOwnRight from "lodash/forOwnRight";

const userData = {
  name: "John",
  age: 25,
  isAdmin: false,
  lastLogin: null
};

forOwnRight(userData, (value, key, obj) => {
  if (value === null || value === undefined) {
    delete obj[key];
  }
});

// userData -> { name: "John", age: 25, isAdmin: false }
//   note: isAdmin: false is KEPT (false is a real value, not nullish)
Try it Yourself

📋 The four-helper family: own/inherited × forward/reverse

HelperInherited keys?DirectionWhen to pick
_.forOwnNoForwardDefault loop over a plain data object.
_.forOwnRightNoReverseOwn-only iteration where last-wins or delete-current semantics matter.
_.forInYesForwardSurface mixin / prototype-provided keys too.
_.forInRightYesReverseMixin + reverse semantics (rare).

All four share the (value, key, object) signature and the return false early-exit rule, so swapping between them is mechanical.

Pitfalls to avoid

Order

“Reverse” refers to key order, not chronological time

If insertion-time semantics matter, use an array of entries and reverse that explicitly instead of leaning on object key order.

Inherited

Picked the wrong helper

If you actually need prototype-provided enumerable keys, use _.forInRight. _.forOwnRight will silently skip them.

Return

Returning a new value does nothing

The iteratee’s return value is only checked for false (early exit). Use _.mapValues or build a result object yourself for transformations.

Falsy

Be careful with falsy guards

if (!value) also deletes 0, "", and false. Use value == null (or an explicit comparison) when you really mean “nullish”.

❓ FAQ

Only the object's own enumerable string-keyed properties, walked from the last key to the first. Inherited keys and symbol keys are skipped.
(value, key, object). Value first, then key, then the original object reference.
Yes. Return false explicitly from the iteratee to stop iteration before every key is visited.
The original object. It is an iteration helper for side effects, not a mapper. Use _.mapValues, _.mapKeys, or _.transform when you need a new object.
Same key coverage (own enumerable string keys only), opposite iteration direction. _.forOwn walks first-to-last; _.forOwnRight walks last-to-first.
_.forOwnRight visits only the object's own enumerable keys. _.forInRight additionally walks inherited enumerable keys from the prototype chain.
Generally yes. Removing the current key while walking backwards never shifts unvisited positions, so it's a natural fit for in-place cleanup.

Summary

Did you know?

_.forOwnRight finishes the four-helper family: forIn / forInRight walk own + inherited keys; forOwn / forOwnRight stick to own keys. The Right suffix only reverses the iteration order—it never changes which keys are visited.

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