I want to deep merge 2 javascript objects with similar properties in a reducer. The catch is the two objects have arrays as their properties and I need them to be concatenated instead of replaced. Basically something like this:
var x = {
name: 'abc',
family: {
children: [
{name: 'xxx'},
{name: 'zzz'}
]
}
};
var y = {
name: 'abc',
family: {
children: [
{name: 'yyy'}
]
}
};
will result on
var y = {
name: 'abc',
family: {
children: [
{name: 'xxx'}, {name: 'zzz'}, {name: 'yyy'}
]
}
};
any suggestion? I prefer lodash based solution if possible. Also, since it's in reducer, I cannot just replace the property with new object