Deep merge Objects in Javascript with Mergerino
artydev
Posted on December 16, 2020
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))
💖 💪 🙅 🚩
artydev
Posted on December 16, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
webdev A Tale of WeakMap and WeakSet in JavaScript: The Guardians of Forgotten Secrets
November 29, 2024