lodash merge array code example

Example 1: lodash deep clone object

const clone = require('lodash/clone'); 
const cloneDeep = require('lodash/clonedeep');

const shallowCopy = clone(originalObject);
const deepCopy = clonedeep(originalObject);

Example 2: lodash merge

import merge from 'lodash/merge'

let object = {  'a': [{ 'b': 2 }, { 'd': 4 }]}; 
let other = {  'a': [{ 'c': 3 }, { 'e': 5 }]}; 
merge(object, other); // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

Example 3: lodash merge array of objects without duplicates

var c = _.map(a, function(obj) {
    return _.assign(obj, _.find(b, {parentId: obj.aId}));
})