JavaScriptIntermediate#objects

How do you deep clone an object?

Use structuredClone for most data, or a recursive clone for custom needs. Spread and Object.assign only copy one level, and JSON round-tripping loses Dates, Maps, functions and undefined.

Example
const deep = structuredClone(obj);
const shallow = { ...obj }; // nested objects still shared

Related Questions

1
JavaScriptIntermediate#es6#operators

What is optional chaining and nullish coalescing?

Open
2
JavaScriptBeginner#fundamentals

Difference between null and undefined?

Open
3
JavaScriptIntermediate#es6#collections

Difference between Map/Set and plain objects/arrays?

Open