Write a value at a nested path. Missing segments are created (arrays for index keys, objects otherwise). Part of Lodash Object (stable — not deprecated). Opposite read helper: _.get.
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.set. Start with this line.
Lodash
_.set(object, path, value)
Call
What it does
_.set(object, path, value)
Primary signature.
_.set(object)
Work with an object’s keys, values, or paths.
Prefer import set from "lodash/set" when you want a smaller bundle.
Custom. Need creation control? Switch to _.setWith.
Compatibility
Browser & Runtime Support
_.set is a Lodash Object helper available in 4.x. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents walk path segments and assign, creating {} / [] along the way.
✓ Stable · Lodash 4.x
_.set()
Available in [email protected] full builds and the lodash/set 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
_.setLodash 4.x
Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import set from "lodash/set" for smaller builds. Use setWith for custom creation; get/result for reads.
Frequently Asked Questions
_.set(object, path, value) writes value at path. Missing path segments are created — arrays for index keys, objects otherwise. Official: _.set(object, 'a[0].b.c', 4) updates the nested c.
Yes. Official docs note that this method mutates object. Clone first if you need immutability.
It returns the same object you passed in (after mutation), which allows chaining like _.set(obj, 'a', 1).a.
Use a string ('a[0].b.c' or 'a.b.c') or an array of keys (['x', '0', 'y', 'z']). Both forms work.
Use _.setWith when you need a customizer to control how missing path segments are created (object vs array).
_.get reads a path without changing the object. _.set writes a path and may create intermediates.