Like _.assign, but accepts a customizer to produce each assigned value. If the customizer returns undefined, assignment is handled normally. Own enumerable string keys only. Since Lodash 4.0.0.
Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.
Syntax
Call _.assignWith. Start with this line.
Lodash
_.assignWith(object, ...sources, customizer)
Call
What it does
_.assignWith(object, ...sources, customizer)
Primary signature.
_.assignWith(object)
Work with an object’s keys, values, or paths.
Prefer import assignWith from "lodash/assignWith" when you want a smaller bundle.
Library declarations
Lodash
_.assignWith(object, ...sources, customizer)
Parameters
Parameter
Description
object
Required. Destination (mutated and returned)
...sources
Optional. Own enumerable string keys only
customizer
Required. Last argument — produces assigned values
Return Value
Return Value
Description
*
The value returned by _.assignWith().
Lodash Examples
Example 1 — Official: Defaults-Style Customizer
Keep existing values; only fill keys that are still undefined.
PickassignWith when you do not want prototype surprises.
Compatibility
Browser & Runtime Support
_.assignWith is a Lodash Object helper (since 4.0.0). It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.
✓ Stable · Lodash 4.0.0+
_.assignWith()
Available in [email protected] full builds and the lodash/assignWith 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
_.assignWithLodash 4.0.0+
Bottom line: Safe for production once Lodash is loaded. Prefer import assignWith from "lodash/assignWith". Use assignInWith when inherited keys matter, or mergeWith for deep custom merges.
Frequently Asked Questions
_.assignWith(object, ...sources, customizer) is like _.assign, but each assigned value can be produced by your customizer. If the customizer returns undefined, Lodash assigns the source value as usual.
Five arguments: (objValue, srcValue, key, object, source).
Same customizer idea. _.assignWith walks own enumerable string keys only; _.assignInWith also walks inherited keys.
Yes. Use _.assignWith({}, ...sources, customizer) when you want a new object.
No. Assignment is shallow. For nested merges with a customizer, use _.mergeWith.
Use import assignWith from "lodash/assignWith" or require("lodash/assignWith"). Full build: import _ from "lodash" then _.assignWith.