๐ŸŒ
Lodash
lodash.info โ€บ doc โ€บ assign
assign - Lodash documentation
Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right.
๐ŸŒ
Dustin John Pfister
dustinpfister.github.io โ€บ 2018 โ€บ 09 โ€บ 21 โ€บ lodash_assign
The _.assign Object method in lodash, and alternatives | Dustin John Pfister at github pages
January 17, 2022 - If I have an object before hand, and pass that as the first argument when calling lodash assign, and then any additional objects that I want to assign down on top of that object, the result will be that the object will be mutated in place.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ lodash-_-assign-method
Lodash _.assign() Method - GeeksforGeeks
October 20, 2023 - Lodash _.assign() method is used to assign the enumerable string keyed properties of the given source objects to the destination objects.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ lodash โ€บ lodash_assign.htm
Lodash - assign method
Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ lodash.assign
lodash.assign - npm
August 13, 2016 - The lodash method _.assign exported as a Node.js module.
      ยป npm install lodash.assign
    
Published: Aug 13, 2016
Version: 4.2.0
๐ŸŒ
Marius Schulz
mariusschulz.com โ€บ blog โ€บ combining-settings-objects-with-lodash-assign-or-merge
Combining Settings Objects with Lodash: _.assign or _.merge? โ€” Marius Schulz
July 28, 2026 - The lodash library contains two similar functions, _.assign and _.merge, that assign property values of some source object(s) to a target object, effectively merging their properties.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ @types โ€บ lodash.assign
@types/lodash.assign - npm
November 7, 2023 - // Generated from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/scripts/generate-modules.ts import { assign } from "lodash"; export = assign;
      ยป npm install @types/lodash.assign
    
Published: Nov 07, 2023
Version: 4.2.9
๐ŸŒ
Lodash
lodash.com โ€บ docs
Lodash Documentation
The iteratee is invoked with four arguments: (accumulator, value, index|key, collection). Many lodash methods are guarded to work as iteratees for methods like _.reduce, _.reduceRight, and _.transform. The guarded methods are: assign, defaults, defaultsDeep, includes, merge, orderBy, and sortBy
๐ŸŒ
Docs-lodash
docs-lodash.com โ€บ v4 โ€บ assign
_.assign โ€“ Lodash Docs v4.17.11
Assigns own enumerable string keyed properties of source objects to the destination object. Source objects are applied from left to right.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ lodash-_-assignwith-method
Lodash _.assignWith() Method - GeeksforGeeks
October 30, 2023 - Lodash _.assign() method is used to assign the enumerable string keyed properties of the given source objects to the destination objects. The source objects are applied from left to right and any subsequent sources overwrite the property assignments ...
Find elsewhere
Top answer
1 of 5
633

Here's how extend/assign works: For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

Here's how merge works: For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination. So essentially we merge object hierarchy from source to destination. While for extend/assign, it's simple one level copy of properties from source to destination.

Here's simple JSBin that would make this crystal clear: http://jsbin.com/uXaqIMa/2/edit?js,console

Here's more elaborate version that includes array in the example as well: http://jsbin.com/uXaqIMa/1/edit?js,console

2 of 5
616

Lodash version 3.10.1

Methods compared

  • _.merge(object, [sources], [customizer], [thisArg])
  • _.assign(object, [sources], [customizer], [thisArg])
  • _.extend(object, [sources], [customizer], [thisArg])
  • _.defaults(object, [sources])
  • _.defaultsDeep(object, [sources])

Similarities

  • None of them work on arrays as you might expect
  • _.extend is an alias for _.assign, so they are identical
  • All of them seem to modify the target object (first argument)
  • All of them handle null the same

Differences

  • _.defaults and _.defaultsDeep processes the arguments in reverse order compared to the others (though the first argument is still the target object)
  • _.merge and _.defaultsDeep will merge child objects and the others will overwrite at the root level
  • Only _.assign and _.extend will overwrite a value with undefined

Tests

They all handle members at the root in similar ways.

_.assign      ({}, { a: 'a' }, { a: 'bb' }) // => { a: "bb" }
_.merge       ({}, { a: 'a' }, { a: 'bb' }) // => { a: "bb" }
_.defaults    ({}, { a: 'a' }, { a: 'bb' }) // => { a: "a"  }
_.defaultsDeep({}, { a: 'a' }, { a: 'bb' }) // => { a: "a"  }

_.assign handles undefined but the others will skip it

_.assign      ({}, { a: 'a'  }, { a: undefined }) // => { a: undefined }
_.merge       ({}, { a: 'a'  }, { a: undefined }) // => { a: "a" }
_.defaults    ({}, { a: undefined }, { a: 'bb' }) // => { a: "bb" }
_.defaultsDeep({}, { a: undefined }, { a: 'bb' }) // => { a: "bb" }

They all handle null the same

_.assign      ({}, { a: 'a'  }, { a: null }) // => { a: null }
_.merge       ({}, { a: 'a'  }, { a: null }) // => { a: null }
_.defaults    ({}, { a: null }, { a: 'bb' }) // => { a: null }
_.defaultsDeep({}, { a: null }, { a: 'bb' }) // => { a: null }

But only _.merge and _.defaultsDeep will merge child objects

_.assign      ({}, {a:{a:'a'}}, {a:{b:'bb'}}) // => { "a": { "b": "bb" }}
_.merge       ({}, {a:{a:'a'}}, {a:{b:'bb'}}) // => { "a": { "a": "a", "b": "bb" }}
_.defaults    ({}, {a:{a:'a'}}, {a:{b:'bb'}}) // => { "a": { "a": "a" }}
_.defaultsDeep({}, {a:{a:'a'}}, {a:{b:'bb'}}) // => { "a": { "a": "a", "b": "bb" }}

And none of them will merge arrays it seems

_.assign      ({}, {a:['a']}, {a:['bb']}) // => { "a": [ "bb" ] }
_.merge       ({}, {a:['a']}, {a:['bb']}) // => { "a": [ "bb" ] }
_.defaults    ({}, {a:['a']}, {a:['bb']}) // => { "a": [ "a"  ] }
_.defaultsDeep({}, {a:['a']}, {a:['bb']}) // => { "a": [ "a"  ] }

All modify the target object

a={a:'a'}; _.assign      (a, {b:'bb'}); // a => { a: "a", b: "bb" }
a={a:'a'}; _.merge       (a, {b:'bb'}); // a => { a: "a", b: "bb" }
a={a:'a'}; _.defaults    (a, {b:'bb'}); // a => { a: "a", b: "bb" }
a={a:'a'}; _.defaultsDeep(a, {b:'bb'}); // a => { a: "a", b: "bb" }

None really work as expected on arrays

Note: As @Mistic pointed out, Lodash treats arrays as objects where the keys are the index into the array.

_.assign      ([], ['a'], ['bb']) // => [ "bb" ]
_.merge       ([], ['a'], ['bb']) // => [ "bb" ]
_.defaults    ([], ['a'], ['bb']) // => [ "a"  ]
_.defaultsDeep([], ['a'], ['bb']) // => [ "a"  ]

_.assign      ([], ['a','b'], ['bb']) // => [ "bb", "b" ]
_.merge       ([], ['a','b'], ['bb']) // => [ "bb", "b" ]
_.defaults    ([], ['a','b'], ['bb']) // => [ "a", "b"  ]
_.defaultsDeep([], ['a','b'], ['bb']) // => [ "a", "b"  ]
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ difference-between-_-assign-_-merge-method-in-lodash
Difference Between _.assign() & _.merge() Method in Lodash - GeeksforGeeks
July 23, 2025 - To use Lodash, first install the package using npm: ... _.assign performs a shallow merge of objects. It copies properties from one or more source objects into a target object, directly modifying the target.
๐ŸŒ
Dustin John Pfister
dustinpfister.github.io โ€บ 2017 โ€บ 11 โ€บ 17 โ€บ lodash_merge
_.merge in lodash as a means to recursively merge down objects. | Dustin John Pfister at github pages
November 25, 2021 - The lodash _.merge differs from lodash _.assign method in that _.assign will create a new object for my deltas overwriting any values that may exist in any lower object.
๐ŸŒ
Salivity
salivity.github.io โ€บ lodash โ€บ article โ€บ top-use-cases-for-lodash-assign-with
Top Use Cases for Lodash assignWith - lodash
The Lodash library provides the _.assignWith method to extend object merging capabilities by allowing developers to define a customizer function.
๐ŸŒ
Lodash
lodash.info โ€บ doc โ€บ assignWith
assignWith - Lodash documentation
function customizer(objValue, srcValue) { return _.isUndefined(objValue) ? srcValue : objValue; } var defaults = _.partialRight(_.assignWith, customizer); defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); // => { 'a': 1, 'b': 2 }
๐ŸŒ
Es-toolkit
es-toolkit.dev โ€บ reference โ€บ compat โ€บ object โ€บ assign.html
assign (Lodash compatibility) | es-toolkit
March 22, 2026 - Use assign when you want to copy properties from one or more source objects to a target object.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ lodash-_-assignin-method
Lodash _.assignIn() Method - GeeksforGeeks
July 15, 2025 - // Defining Lodash variable const _ = require('lodash'); function Gfg1() { this.a = 1; } function Gfg2() { this.c = 3; } Gfg1.prototype.b = 10; Gfg2.prototype.d = 40; console.log(_.assignIn({ a: 4 }, new Gfg1, new Gfg2));