Deep Clone Object

Create a deep copy using structuredClone or JSON.

Code

JavaScript
// Modern: structuredClone (Node 17+, browsers)
const cloned = structuredClone(obj);

// Fallback: JSON (loses functions, undefined, Date)
const cloned2 = JSON.parse(JSON.stringify(obj));

// Shallow clone
const shallow = { ...obj };

Line-by-line explanation

Expected output

Deep copy of obj

Related snippets

Related DuskTools