Deep clone an object

structuredClone copies nested objects, Dates, Maps and Sets correctly.

javascript beginner #objects#data
Apri nel playground
js-structured-clone.js
const original = { user: { name: "Ada" }, created: new Date(), tags: new Set(["js"]) };
const copy = structuredClone(original);

copy.user.name = "Grace";
console.log(original.user.name);          // Ada (unchanged)
console.log(copy.created instanceof Date); // true
console.log([...copy.tags]);