Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

JavaScript Deep Copy JSON parse & stringify

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 = JSON.parse(JSON.stringify(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