Updating Deep Immutable Object
let newVersion = {
language: 'Default Language', // Set default for unspecified properties
...previousVersion,
name: 'New Name', // Override the name property
address: {
...previousVersion.address,
zipCode: '99999' // Update nested zip code
},
items: [
{title: 'New First Item'}, // Add an item to the beginning of items
...previousVersion.items,
{title: 'New Last Item'} // Add an item to the end of items
],
};
What if you wanted to update a title of an item from items?