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])
Call
What 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
Parameter
Description
object
Required. The object to iterate over
iteratee
Optional. Invoked per key; default _.identity
Return Value
Return Value
Description
*
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)
Choose. Use forOwnRight when reverse order matters.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.forOwnLodash 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.