This method is like _.update except that it accepts a customizer which is invoked to produce the objects of path. If customizer returns undefined, path creation is handled by the method instead. Part of Lodash 4.x Object (since 4.6.0).
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.updateWith. Start with this line.
Lodash
_.updateWith(object, path, updater, [customizer])
Call
What it does
_.updateWith(object, path, updater, [customizer])
Primary signature.
_.updateWith(object)
Work with an object’s keys, values, or paths.
Prefer import updateWith from "lodash/updateWith" when you want a smaller bundle.
Library declarations
Lodash
_.updateWith(object, path, updater, [customizer])
Parameters
Parameter
Description
object
Required. Target object (mutated)
path
Required. Dot/bracket string or key array
updater
Required. (value) => newValue for the leaf
customizer
Optional. Creates missing intermediate containers
Return Value
Return Value
Description
*
The same object reference
Lodash Examples
Example 1 — Official: Object Customizer
Force nested objects for index-looking keys.
Lodash
var object = {};
_.updateWith(object, "[0][1]", _.constant("a"), Object);
// → { "0": { "1": "a" } }
See how the customizer changes the shape of missing segments.
Lodash
var a = {};
var b = {};
_.updateWith(a, "[0][1]", _.constant("x"));
// arrays for index-like keys
_.updateWith(b, "[0][1]", _.constant("x"), Object);
// objects for those keys
JSON.stringify(a);
// → {"0":[null,"x"]} (shape may vary by engine fill)
JSON.stringify(b);
// → {"0":{"1":"x"}}
updateWith. Needed to force object (or other) containers.
Same updater. Leaf logic is identical.
Twin. Mirrors set / setWith.
Compatibility
Browser & Runtime Support
_.updateWith is a Lodash Object helper (since 4.6.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. It pairs _.update with the customizer hook from _.setWith; there is no single native equivalent.
✓ Stable · Lodash 4.x
_.updateWith()
Available in [email protected] full builds and the lodash/updateWith 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
_.updateWithLodash 4.6+
Bottom line: Safe for production once Lodash is loaded. Prefer import updateWith from "lodash/updateWith" for smaller builds. Use it when missing path segments must be objects (or other custom containers).
Frequently Asked Questions
Like _.update: it runs an updater on the value at path and writes the result back. It also accepts a customizer that builds missing intermediate containers along the path.
update uses Lodash defaults for missing segments. updateWith lets you customize those containers — same idea as set vs setWith.
It creates missing intermediates: (nsValue, key, nsObject) => container. It does not transform the leaf — the updater does.
Lodash falls back to defaults: numeric indexes become arrays; other keys become plain objects.
Yes. It mutates in place and returns the same object. Clone first when immutability matters.
Use import updateWith from "lodash/updateWith" or require("lodash/updateWith"). Full build: import _ from "lodash" then _.updateWith.