JavaScript Deep Copy StructuredClone()

node v17.9.1
version: 2.0.0
endpointsharetweet
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);
Loading…

no comments

    sign in to comment