_.mergeWith(object, sources, customizer)
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).Note: This method mutates object
.
Since
4.0.0
Arguments
object
(Object): The destination object.sources
(…Object): The source objects.customizer
(Function): The function to customize assigned values.
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(object, other, customizer);// => { 'a': [1, 3], 'b': [2, 4] }
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .