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)
Call
What 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
Parameter
Description
object
Required. Destination (mutated and returned)
...sources
Optional. Own enumerable string keys to copy
Return Value
Return Value
Description
*
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 }
Assign. Copies the nested property as a reference.
Mutate. Changing result.nested changes the original.
Shallow. Only the top-level keys are new on result.
Deep? Use _.merge or clone nested values yourself.
Compatibility
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 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
_.assignLodash 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.