To merge objects in JS, you can use Object.assign.
The problem with is that it only accomplishes 'shallow merge'.
It does not take in account nested properties.
In my scripts I use Mergerino to get things done.
You can test it here : Merge
const merge = mergerino
const user = {
name: 'David',
phone: 122345678,
location: {
city: 'Camden',
country: 'UK'
}
};
const updates = {
location: {
city: 'Smithfield'
}
};
console.log(Object.assign({}, user, updates));
console.log(merge(user, updates))