Merge

Merges the properties of the source object into the target object, performing a deep merge.

CategoryObjects
AuthorPol Gubau
Since1.0.0
Last Updated2025-03-15
TypeSync
CompatibilityUniversal

Example

  • Input

    merge(
    	{a: 1, b: { x: 1 } }, 
    	{ b: { y: 2 }, 
    	c: 3 })

    Output:

    {	a: 1, 
    	b: { x: 1, y: 2 }, 
    	c: 3 }

Return

The updated target object with properties from the source object merged in.

Type: T & S

Props

NameTypeDefaultRequiredDescription
targetTnullYesThe target object into which the source object properties will be merged. This object is modified in place.
sourceSnullYesThe source object whose properties will be merged into the target object.

Notes

This function mutates the target object. If a property in the source is undefined, it does not overwrite a defined property in the target.

Tags

  • merge
  • deep merge
  • object
  • recursive
  • modification

Related