Ask any question about JavaScript here... and get an instant response.
Post this Question & Answer:
How do you deep clone an object in JavaScript without using JSON methods?
Asked on Feb 24, 2026
Answer
To deep clone an object in JavaScript without using JSON methods, you can use structured cloning via the structuredClone function, which is a modern and safe way to perform deep cloning.
<!-- BEGIN COPY / PASTE -->
const originalObject = {
name: "John",
age: 30,
details: {
hobbies: ["reading", "gaming"],
address: {
city: "New York",
zip: "10001"
}
}
};
const clonedObject = structuredClone(originalObject);
console.log(clonedObject);
// Output: { name: "John", age: 30, details: { hobbies: ["reading", "gaming"], address: { city: "New York", zip: "10001" } } }
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with JavaScript best practices.- The structuredClone function is part of the modern JavaScript standard and is supported in most modern browsers.
- It handles various data types, including objects, arrays, and more complex structures like Maps and Sets.
- This method is preferred over JSON methods as it can clone objects with non-serializable properties like functions and symbols.
- Always ensure your environment supports structuredClone, as it's a relatively new addition to JavaScript.
Recommended Links:
