Explorer
Node.js

Write a function `deepClone(obj)` that creates a deep copy of a plain object (no functions, no circular refs). Use `structuredClone` or JSON methods.

Problem Statement

Write a function `deepClone(obj)` that creates a deep copy of a plain object (no functions, no circular refs). Use `structuredClone` or JSON methods.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: Shallow copy ({...obj}) only copies top-level properties. šŸ’” Hint 2: JSON.parse(JSON.stringify(obj)) creates a deep clone for plain objects. šŸ’” Hint 3: return JSON.parse(JSON.stringify(obj)); āœ… Solution: ```javascript function deepClone(obj) { return JSON.parse(JSON.stringify(obj)); } ```

Deep Clone an Object

Easy
Write a function `deepClone(obj)` that creates a deep copy of a plain object (no functions, no circular refs). Use `structuredClone` or JSON methods.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
{"orig":2,"clone":99}