merge source npm

_.merge(object, [sources])

Recursively merges own and inherited enumerable properties of source objects into the destination object, skipping source properties that resolve to undefined. Array and plain object properties are merged recursively. Other objects and value types are overriden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

Note: This method mutates object.

Arguments

  1. object (Object)

    The destination object.

  2. [sources] (...Object)

    The source objects.

Returns (Object)

Returns object.

Example

var users = {
  'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
};

var ages = {
  'data': [{ 'age': 36 }, { 'age': 40 }]
};

_.merge(users, ages);
// => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }