Lodash _.forOwn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Iterates over own enumerable string-keyed properties of object and invokes iteratee for each. Inherited prototype keys are skipped. Part of Lodash Object since 0.3.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 _.forOwn. Start with this line.

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

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

Library declarations
Lodash
_.forOwn(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: Own Keys Only

Prototype key c is skipped; own keys a and b are logged.

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

Foo.prototype.c = 3;

_.forOwn(new Foo, function(value, key) {
  console.log(key);
});
// → Logs 'a' then 'b'
//    (iteration order is not guaranteed)
Try It Yourself

How It Works

  1. Instance. Own keys a and b; prototype key c.
  2. forOwn. Visits only own enumerable string keys.
  3. Skip. Inherited c is never passed to the iteratee.
  4. Result. Logs a then b (order not guaranteed).

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

Same object; forIn includes the prototype key.

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

var own = [];
var all = [];

_.forOwn(new Foo(), function (v, k) { own.push(k); });
_.forIn(new Foo(), function (v, k) { all.push(k); });

// own → ["a", "b"]
// all → ["a", "b", "c"]
Try It Yourself

How It Works

  1. Collect keys. Push each visited key into an array.
  2. forOwn. Only own keys → a, b.
  3. forIn. Also visits inherited c.
  4. Choose. Use forOwn when prototype keys must be ignored.

Example 3 — Iterate Values Too

The iteratee receives value and key on every step.

Lodash
var user = { name: "Ada", age: 36, city: "London" };
var pairs = [];

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

// pairs → ["name=Ada", "age=36", "city=London"]
Try It Yourself

How It Works

  1. Plain object. Three own enumerable keys.
  2. Iteratee. Builds key=value strings.
  3. No prototype. Nothing inherited is visited.
  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 = [];

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

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

How It Works

  1. Start. Visit a, then b.
  2. Stop. On b, return false.
  3. Skip. c is never visited.
  4. Note. Only an explicit false breaks — other falsy returns do not.

Example 5 — vs _.forOwnRight

Same own keys; opposite walk order.

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

_.forOwn(obj, function (v, k) { left.push(k); });
_.forOwnRight(obj, function (v, k) { right.push(k); });

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

How It Works

  1. Same set. Both visit only own keys.
  2. forOwn. Typical forward order a → b → c.
  3. forOwnRight. Opposite sequence.
  4. Choose. Use forOwnRight when reverse order matters.

Browser & Runtime Support

_.forOwn is a Lodash Object helper (available since 0.3.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 0.3.0+

_.forOwn()

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

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

Frequently Asked Questions

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

Next: _.forOwnRight()

Iterate an object’s own enumerable string keys in reverse order.

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