The initial object which should be updated with values from the target
Optional
other: object = {}A new object whose values should replace those in the source
Optional
options: {Additional options which configure the merge
Optional
enforceTypes?: booleanControl whether strict type checking requires that the value of a key in the other object must match the data type in the original data to be merged.
Optional
inplace?: booleanControl whether to apply updates to the original object in-place (if true), otherwise the original object is duplicated and the copy is merged.
Optional
insertKeys?: booleanControl whether to insert new top-level objects into the resulting structure which do not previously exist in the original object.
Optional
insertValues?: booleanControl whether to insert new nested values into child objects in the resulting structure which did not previously exist in the original object.
Optional
overwrite?: booleanControl whether to replace existing values in the source, or only merge values which do not already exist in the original object.
Optional
performDeletions?: booleanControl whether to perform deletions on the original object if deletion keys are present in the other object.
Optional
recursive?: booleanControl whether to merge inner-objects recursively (if true), or whether to simply replace inner objects with a provided new value.
Optional
_d: number = 0A privately used parameter to track recursion depth.
The original source object including updated, inserted, or overwritten records.
mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: false}); // {k1: "v1"}
mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: true}); // {k1: "v1", k2: "v2"}
mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: false}); // {k1: {i1: "v1"}}
mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: true}); // {k1: {i1: "v1", i2: "v2"}}
mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: true}); // {k1: "v2"}
mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: false}); // {k1: "v1"}
mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: false}); // {k1: {i2: "v2"}}
mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: true}); // {k1: {i1: "v1", i2: "v2"}}
Update a source object by replacing its keys and values with those from a target object.