JavaScript Deep Copy StructuredClone()
const myBrowser = {
language: 'JavaScript',
framework: 'Angular',
browser: 'Brave',
os: 'Windows 11',
date: {
time: new Date().getTime(),
date: null
}
}
const myBrowserCopy = structuredClone(myBrowser);
console.log('before myBrowser:', myBrowser);
console.log('before myBrowserCopy:', myBrowserCopy);
myBrowserCopy.browser = 'Chrome';
console.log('after update myBrowser:', myBrowser);
console.log('after update myBrowserCopy:', myBrowserCopy);
myBrowser.date.date = new Date();
console.log('after update original myBrowser:', myBrowser);
console.log('after update original myBrowserCopy:', myBrowserCopy);
no comments