structuredClone() is the modern, built-in way to deep copy objects. No more JSON.parse(JSON.stringify()) hacks.
The Old Way (and its problems)
structuredClone (Modern Way)
What structuredClone Supports
- ✅ Nested objects and arrays
- ✅ Date, RegExp, Blob, File
- ✅ Map, Set
- ✅ ArrayBuffer, TypedArrays
- ✅ Circular references (!)
- ❌ Functions (throws error)
- ❌ DOM elements
- ❌ Symbol properties (ignored)
- ❌ Prototype chain (lost)
- ❌ Property descriptors (getter/setter lost)
Circular References
Performance Comparison
When to Use What
- Shallow copy: spread operator (
{ ...obj }) - Deep copy:
structuredClone() - Copy with functions: manual implementation or lodash.cloneDeep
- Immutable updates: Immer library