Merge
Merges the properties of the source object into the target object, performing a deep merge.
Category | Objects |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
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
Name | Type | Default | Required | Description |
---|---|---|---|---|
target | T | null | Yes | The target object into which the source object properties will be merged. This object is modified in place. |
source | S | null | Yes | The 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
- arrays
- universal
- sync
- Since 1.0.0
- validations
- universal
- sync
- Since 1.0.0
- objects
- universal
- sync
- Since 1.0.0
groupBy
Groups the elements of an array based on a provided key-generating function.
isObject
Checks if the provided parameter is a plain object.
cloneDeep
Deep clone an object. A deep clone is a clone of the source object and all of its children, and their children, and so on.