[Javascript] structuredClone - deep clone object
const calendarEvent = {
title: 'abc submit',
date: new Date(123),
attendees: ["Steve", {name: 'Steve'}]
}
const copied = structuredClone(calendarEvent)
copied.attendees.push('Zwan')
copied.attendees[1].name = 'Zwan'
console.log(calendarEvent, copied)
/*
{
"title": "abc submit",
"date": "1970-01-01T00:00:00.123Z",
"attendees": [
"Steve",
{
"name": "Steve"
}
]
}, {
"title": "abc submit",
"date": "1970-01-01T00:00:00.123Z",
"attendees": [
"Steve",
{
"name": "Zwan"
},
"Zwan"
]
}
*/