Merge two or more objects deeply.
- Source
Methods
(inner) all(array, options) → {Array|object}
Merges an array of arrays or objects using deepMerge
into one array or object.
Name | Type | Description |
---|---|---|
array | Array | The array of arrays or objects to deep merge. |
options | object | Options object. |
- Source
Returns a new array or object, after merging all items in the array.
- Type:
- Array |
object
import { deepMerge } from "@gravityforms/utils";
function Example() {
const array = [
{
foo: { bar: 3 },
array: [ 1, 2, 3 ],
},
{
foo: { baz: 4, bar: 5 },
quux: 5,
array: [ 4, 5, 6 ],
},
{
foo: { baz: 1 },
array: [ 7, 8, 9 ],
},
];
const output = deepMerge.all( array );
}
(inner) deepMerge(target, source, options) → {Array|object}
Merge two objects x and y deeply, returning a new merged object with the elements from both x and y. If an element at the same key is present for both x and y, the value from y will appear in the result. Merging creates a new object, so that neither x or y is modified. Note: By default, arrays are merged by concatenating them.
Taken and adapted from https://www.npmjs.com/package/deepmerge
Name | Type | Description |
---|---|---|
target | Array | | The original array or object to merge to. |
source | Array | | The new array or object that will get priority when keys match. |
options | object | Options object. |
- Since
- 1.0.0
- Source
- module:isFunction
- module:defaultIsMergeableObject
Returns a new array or object, after merging target and source.
- Type:
- Array |
object
import { deepMerge } from "@gravityforms/utils";
function Example() {
const target = {
foo: { bar: 3 },
array: [ 1, 2, 3 ]
};
const source = {
foo: { baz: 4, bar: 5 },
quux: 5,
array: [ 4, 5, 6 ],
};
const output = deepMerge( target, source );
}