JS Built-ins
structuredClonebeginner

Deep Clone an Object

πŸ“– Usage Example
const obj = { a: 1, b: { c: 2 } }
const clone = structuredClone(obj)
clone.b.c = 99
obj.b.c  // β†’ 2 (original unchanged)

structuredClone() creates a deep clone so modifying the copy does not affect the original.

Use structuredClone() to create a deep copy of a plain object.

πŸ’‘ Hints (1)
  • β€’ structuredClone() performs a deep copy