Lodash _.assignIn() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Like _.assign, but iterates over own and inherited enumerable source properties. Alias: _.extend. 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 _.assignIn. Start with this line.

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

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

Library declarations
Lodash
_.assignIn(object, ...sources)

Parameters

ParameterDescription
objectRequired. Destination (mutated and returned)
...sourcesOptional. Own + inherited enumerable string keys

Return Value

Return ValueDescription
*The mutated object

Lodash Examples

Example 1 — Official: Own + Inherited Keys

Prototype properties are copied along with own instance keys.

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

function Bar() {
  this.c = 3;
}

Foo.prototype.b = 2;
Bar.prototype.d = 4;

_.assignIn({ 'a': 0 }, new Foo, new Bar);
// → { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
Try It Yourself

How It Works

  1. Own keys. a from Foo and c from Bar are copied.
  2. Inherited. b and d come from each prototype.
  3. Overwrite. Destination a: 0 becomes a: 1.
  4. Result. All four string keys land on the destination.

Example 2 — assignIn vs assign

Same inputs; only assignIn keeps prototype keys.

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

_.assign({}, new Foo());
// → { a: 1 }

_.assignIn({}, new Foo());
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. assign. Own keys only → just a.
  2. assignIn. Also walks the prototype → includes b.
  3. Same shallow rules. Nested values are still by reference.
  4. Choose. Use assignIn when prototype data matters.

Example 3 — Alias _.extend

_.extend is the same function as _.assignIn.

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

_.extend({}, new Foo());
// → { a: 1, b: 2 }

_.extend === _.assignIn;
// → true
Try It Yourself

How It Works

  1. Alias. Docs list _.extend → assignIn.
  2. Same call. Behavior matches _.assignIn exactly.
  3. Identity. In the full build, they are the same function.
  4. Style. Prefer assignIn in new code; extend is fine in older codebases.

Example 4 — Non-Mutating Pattern

Pass {} as the destination to leave sources untouched.

Lodash
function User() {
  this.name = 'Ada';
}
User.prototype.role = 'admin';

var user = new User();
var copy = _.assignIn({}, user);
// → { name: 'Ada', role: 'admin' }

// user is unchanged
Try It Yourself

How It Works

  1. Empty target. {} receives the copies.
  2. Own + proto. name and role both land on copy.
  3. Flattened. Inherited role becomes an own key on the result.
  4. Safe. Original instance is not mutated.

Example 5 — Later Sources Win

Conflicts resolve left to right, including inherited keys.

Lodash
function A() { this.x = 1; }
A.prototype.y = 2;

function B() { this.x = 9; }
B.prototype.z = 3;

_.assignIn({}, new A(), new B());
// → { x: 9, y: 2, z: 3 }
Try It Yourself

How It Works

  1. First source. Adds x: 1 and inherited y: 2.
  2. Second source. Overwrites x to 9 and adds z.
  3. Order. Rightmost source wins for each key.
  4. Same as assign. Only the key set (own vs inherited) differs.

Browser & Runtime Support

_.assignIn is a Lodash Object helper (available since 4.0.0, stable in 4.x; alias _.extend). 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+

_.assignIn()

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

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

Frequently Asked Questions

_.assignIn(object, ...sources) copies own and inherited enumerable string-keyed properties from each source onto object, left to right. Later sources overwrite earlier keys. It returns the mutated object.
Yes. _.extend is the documented alias of _.assignIn. Same function, two names.
_.assign copies own keys only. _.assignIn also copies enumerable inherited keys from the prototype chain.
Yes. Use _.assignIn({}, a, b) when you want a new object.
No. It is shallow — nested objects and arrays are copied by reference. Use _.merge for recursive plain-object merges.
Use import assignIn from "lodash/assignIn" or require("lodash/assignIn"). Full build: import _ from "lodash" then _.assignIn or _.extend.

Next: _.assignInWith()

Like _.assignIn, but with a customizer to decide each assigned value.

_.assignInWith() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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