Lodash _.assign() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Assigns own enumerable string-keyed properties from source objects to a destination object. Sources apply left to right; later sources overwrite earlier ones. Part of Lodash Object since 0.10.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 _.assign. Start with this line.

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

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

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

Parameters

ParameterDescription
objectRequired. Destination (mutated and returned)
...sourcesOptional. Own enumerable string keys to copy

Return Value

Return ValueDescription
*The mutated object

Lodash Examples

Example 1 — Official: Own Keys Only

Prototype properties are skipped; own keys from each instance are copied.

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

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

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

_.assign({ 'a': 0 }, new Foo, new Bar);
// → { 'a': 1, 'c': 3 }
Try It Yourself

How It Works

  1. Instances. new Foo has own a; new Bar has own c.
  2. Prototypes. b and d live on the prototype — not copied.
  3. Overwrite. Source a: 1 replaces destination a: 0.
  4. Need inherited? Use _.assignIn.

Example 2 — Later Sources Win

When keys overlap, the rightmost source value is kept.

Lodash
var target = { a: 1, b: 2 };

_.assign(target, { b: 4 }, { c: 5 });
// → { a: 1, b: 4, c: 5 }

// target is the same object (mutated)
Try It Yourself

How It Works

  1. Start. Destination is { a: 1, b: 2 }.
  2. First source. Sets b to 4.
  3. Second source. Adds c: 5.
  4. Return. Same reference as target.

Example 3 — Non-Mutating Pattern

Pass {} as the destination to build a new object.

Lodash
var defaults = { theme: 'light', lang: 'en' };
var overrides = { theme: 'dark' };

var config = _.assign({}, defaults, overrides);
// → { theme: 'dark', lang: 'en' }

// defaults is unchanged
Try It Yourself

How It Works

  1. Empty target. {} receives all copies.
  2. Defaults first. Base values land on the new object.
  3. Overrides second. theme is replaced.
  4. Safe. Original defaults / overrides stay intact.

Example 4 — Multiple Sources

Any number of sources can be listed; order decides conflicts.

Lodash
_.assign(
  {},
  { a: 1 },
  { b: 2 },
  { a: 9, c: 3 }
);
// → { a: 9, b: 2, c: 3 }
Try It Yourself

How It Works

  1. First source. Sets a: 1.
  2. Second. Adds b: 2.
  3. Third. Overwrites a to 9 and adds c.
  4. Rule. Rightmost source wins for each key.

Example 5 — Shallow Nested Copy

Nested objects are shared by reference — not deep-cloned.

Lodash
var nested = { x: 1 };
var result = _.assign({}, { nested: nested });

result.nested.x = 99;
// nested.x is also 99

// Need deep merge? use _.merge
Try It Yourself

How It Works

  1. Assign. Copies the nested property as a reference.
  2. Mutate. Changing result.nested changes the original.
  3. Shallow. Only the top-level keys are new on result.
  4. Deep? Use _.merge or clone nested values yourself.

Browser & Runtime Support

_.assign is a Lodash Object helper (available since 0.10.0, stable in 4.x). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Loosely based on native Object.assign (ES2015).

✓ Stable · Lodash 0.10.0+

_.assign()

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

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import assign from "lodash/assign" for smaller builds. Native alternative: Object.assign (includes symbol keys).

Frequently Asked Questions

_.assign(object, ...sources) copies own enumerable string-keyed properties from each source onto object, left to right. Later sources overwrite earlier keys. It returns the mutated object.
Yes. It writes into the first argument. Use _.assign({}, a, b) when you want a new object.
Shallow. Nested objects and arrays are copied by reference. Use _.merge for recursive plain-object merging.
Both are shallow and mutate the target. Native Object.assign also copies symbol keys; Lodash _.assign copies only string keys. Both skip inherited prototype keys.
_.assign copies own keys only. _.assignIn (alias _.extend) also copies enumerable inherited keys from the prototype chain.
Use import assign from "lodash/assign" or require("lodash/assign"). Full build: import _ from "lodash" then _.assign.

Next: _.assignIn()

Like _.assign, but also copies enumerable inherited properties.

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