Merge Deep
Merges and deep copies the values of all enumerable own properties of the target object from the source object to a new object.
Category | Objects |
Author | Pol Gubau |
Since | 1.0.0 |
Last Updated | 2025-03-15 |
Type | Sync |
Compatibility | Universal |
Example
Input
mergeDeep({ a: { x: 1 } }, { a: { y: 2 }, b: 3 })
Output:
{ a: { x: 1, y: 2 }, b: 3 }
Return
A new object that is the result of merging and deeply copying properties from the source object into the target object.
Type: T & S
Props
Name | Type | Default | Required | Description |
---|---|---|---|---|
target | T extends object | null | Yes | The target object from which to copy properties. |
source | S extends object | null | Yes | The source object from which to merge properties. |
Notes
This function creates a new object by merging and deep copying properties from the source object into the target object. It performs a deep merge, meaning nested objects are merged recursively. If a nested object is found in both the target and source, it will be recursively merged. If the source object is empty, a deep copy of the target is returned.
Tags
- merge
- deep merge
- object
- recursive
- copy
- modification