Lodash _.assignInWith() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Like _.assignIn, but accepts a customizer to produce each assigned value. If the customizer returns undefined, assignment is handled normally. Alias: _.extendWith. Part of Lodash Object since 4.0.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 _.assignInWith. Start with this line.

Lodash
_.assignInWith(object, ...sources, customizer)
CallWhat it does
_.assignInWith(object, ...sources, customizer)Primary signature.
_.assignInWith(object)Work with an object’s keys, values, or paths.

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

Library declarations
Lodash
_.assignInWith(object, ...sources, customizer)

Parameters

ParameterDescription
objectRequired. Destination (mutated and returned)
...sourcesOptional. Own + inherited enumerable string keys
customizerRequired. Last argument — produces assigned values

Return Value

Return ValueDescription
*The value returned by _.assignInWith().

Lodash Examples

Example 1 — Official: Defaults-Style Customizer

Keep existing values; only fill keys that are still undefined.

Lodash
function customizer(objValue, srcValue) {
  return _.isUndefined(objValue) ? srcValue : objValue;
}

var defaults = _.partialRight(_.assignInWith, customizer);

defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// → { 'a': 1, 'b': 2 }
Try It Yourself

How It Works

  1. Customizer. Prefer the destination value when it is defined.
  2. partialRight. Binds the customizer as the last argument.
  3. Sources. { b: 2 } fills a missing key; { a: 3 } cannot overwrite a: 1.
  4. Related. Similar idea to _.defaults for own keys.

Example 2 — Direct assignInWith Call

Same customizer without partialRight.

Lodash
function customizer(objValue, srcValue) {
  return _.isUndefined(objValue) ? srcValue : objValue;
}

_.assignInWith({ a: 1 }, { b: 2 }, { a: 3 }, customizer);
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. Last arg. The customizer must be the final argument.
  2. Sources in the middle. Any number of sources can appear before it.
  3. Same rule. Keep defined destination values; take sources for missing keys.
  4. Mutates. The first object is updated in place.

Example 3 — Without Customizer (assignIn)

Plain assignIn overwrites; the customizer can prevent that.

Lodash
_.assignIn({ a: 1 }, { a: 3, b: 2 });
// → { a: 3, b: 2 }

_.assignInWith({ a: 1 }, { a: 3, b: 2 }, function (objValue, srcValue) {
  return _.isUndefined(objValue) ? srcValue : objValue;
});
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. assignIn. Later source wins → a becomes 3.
  2. assignInWith. Customizer keeps a: 1.
  3. New keys. b is still filled because it was undefined.
  4. Use. Reach for With when overwrite rules are not “last wins”.

Example 4 — Alias _.extendWith

_.extendWith is the same function as _.assignInWith.

Lodash
function customizer(objValue, srcValue) {
  return _.isUndefined(objValue) ? srcValue : objValue;
}

_.extendWith({ a: 1 }, { b: 2 }, { a: 3 }, customizer);
// → { a: 1, b: 2 }

_.extendWith === _.assignInWith;
// → true
Try It Yourself

How It Works

  1. Alias. Docs list _.extendWith → assignInWith.
  2. Same call. Behavior matches exactly.
  3. Identity. In the full build they are the same function.
  4. Style. Prefer assignInWith in new code.

Example 5 — Inherited Source Keys

Like assignIn, prototype keys are included — then customized.

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

function customizer(objValue, srcValue) {
  return _.isUndefined(objValue) ? srcValue : objValue;
}

_.assignInWith({ a: 9 }, new Foo(), customizer);
// → { a: 9, b: 2 }

_.assignWith({ a: 9 }, new Foo(), customizer);
// → { a: 9 }   // own keys only — no b
Try It Yourself

How It Works

  1. Own key. Source a: 1 does not overwrite destination a: 9.
  2. Inherited. Prototype b: 2 is still a candidate key.
  3. Fill. b was undefined on the destination → assigned.
  4. assignWith. Skips inherited b entirely.

Browser & Runtime Support

_.assignInWith is a Lodash Object helper (available since 4.0.0, stable in 4.x; alias _.extendWith). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.0.0+

_.assignInWith()

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

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import assignInWith from "lodash/assignInWith" for smaller builds. Use _.assignWith when you only need own keys.

Frequently Asked Questions

_.assignInWith(object, ...sources, customizer) is like _.assignIn, but each assigned value can be produced by your customizer. If the customizer returns undefined, Lodash assigns the source value as usual.
Yes. _.extendWith is the documented alias of _.assignInWith.
Five arguments: (objValue, srcValue, key, object, source).
Same customizer idea. _.assignInWith walks own and inherited enumerable string keys; _.assignWith walks own keys only.
Yes. Use _.assignInWith({}, ...sources, customizer) when you want a new object.
Use import assignInWith from "lodash/assignInWith" or require("lodash/assignInWith"). Full build: import _ from "lodash" then _.assignInWith or _.extendWith.

Next: _.assignWith()

Like _.assign, but with a customizer for each assigned own-key value.

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