Skip to main content

assignWith

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

This method is like _.assign except that it accepts customizer



which is invoked to produce the assigned values. If customizer returns



undefined, assignment is handled by the method instead. The customizer



is invoked with five arguments: (objValue, srcValue, key, object, source).




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) {
return _.isUndefined(objValue) ? srcValue : objValue;
}

var defaults = _.partialRight(_.assignWith, customizer);

defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }