JavaScript structuredClone()
Published Feb 24, 2025
Contribute to Docs
In JavaScript, the structuredClone() method under the Window interface creates a deep copy of a JavaScript value, supporting circular references and built-in types that cannot be handled by the stringify() and parse() methods in JSON.
Syntax
structuredClone(value)
value: The JavaScript value to be deep-cloned. It can be an object, array, map, set, or other structured data types.
This method returns a new deep copy of the provided value, with all nested objects and special types properly cloned.
Example
The following example shows how structuredClone() deep copies a nested object, preserving the original structure while allowing independent modifications:
// Create an object with nested propertiesconst original = {numbers: [1, 2, 3],nested: {name: 'Example',},};// Clone the objectconst clone = structuredClone(original);// Modify the cloneclone.numbers.push(4);clone.nested.name = 'Modified';console.log(original.numbers);console.log(clone.numbers);console.log(original.nested.name);console.log(clone.nested.name);
The output of the above code will be:
[1, 2, 3][1, 2, 3, 4]ExampleModified
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours