I have two objects:
var one = {
addedItems: [0, 1],
removedItems: [8, 9],
oneTwo: false,
someStuff: {
anotherArray: ['a', 'b']
}
};
var two = {
addedItems: [3, 4],
removedItems: [6, 7],
someStuff: {
anotherArray: ['c', 'd']
}
};
And in the end I need to merge these two objects and get something like this:
{
addedItems: [0, 1, 3, 4],
removedItems: [8, 9, 6, 7],
oneTwo: false,
someStuff: {
anotherArray: ['a', 'b', 'c', 'd']
}
}
The operation should be performed on objects with different structure.
What is the best way (or just possible way) to do this? Are there any methods in jQuery or underscore/lodash that allow to do this?
a.foo:trueandb.foo:falsewhich one takes precedence when the values are atomic? Likewise if the values in the array contain duplicates do you want duplicates or just unique values?deepmergelibrary. Here is a blog (published yesterday) about it.