Skip to main content

mergeWith

_.mergeWith(customizer, object, sources) # Ⓢ [Ⓣ][1] Ⓝ

This method is like _.merge except that it accepts customizer which



is invoked to produce the merged values of the destination and source



properties. If customizer returns undefined, merging is handled by the



method instead. The customizer is invoked with six arguments:



(objValue, srcValue, key, object, source, stack).




Since​

4.0.0

Arguments​

  1. customizer (Function): The function to customize assigned values.
  2. object (Object): The destination object.
  3. sources (Object|Object[]): The source objects.

Returns​

(Object): Returns object.

Example​

function customizer(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}

var object = { 'a': [1], 'b': [2] };
var other = { 'a': [3], 'b': [4] };

_.mergeWith(customizer, object, other);
// => { 'a': [1, 3], 'b': [2, 4] }