Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
For ordinary data that the JavaScript structured clone algorithm supports, use structuredClone(value):
const copy = structuredClone(value);
It creates a deep copy, including nested data, and can reproduce circular references. It does not preserve every JavaScript object’s behavior, so the right method depends on what the object contains.
Use structuredClone() for nested data
structuredClone() is the built-in option for copying many common JavaScript values without retaining references to the original nested objects. For example:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →const original = {
user: { name: "Ada" },
tags: ["typescript", "javascript"],
};
const copy = structuredClone(original);
copy.user.name = "Grace";
// original.user.name remains "Ada"
Changing the nested object in the copy does not change the corresponding nested object in the original. The method is part of the JavaScript runtime, not a TypeScript-only feature. See MDN’s documentation for the structuredClone() method.
#1 Best Overall
What it can clone
Structured-cloneable values include plain objects and arrays, as well as built-ins such as dates, maps, sets, array buffers, data views, typed arrays, regular expressions, and errors. Primitive values other than symbols are supported too. See MDN’s list of types handled by the structured clone algorithm.
Cloning circular references
A circular reference points back to an object already encountered—for example, an object whose self property refers to itself. structuredClone() supports cycles by tracking references it has already visited:
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
const original: { label: string; self?: unknown } = { label: "node" };
original.self = original;
const copy = structuredClone(original);
// The cloned self-reference points back to copy.
The copied cycle points within the copy rather than back to the original. A simple recursive copying function may fail on cycles unless it also tracks previously visited objects.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Know what the clone does not preserve
A deep copy does not necessarily mean a behaviorally identical object. The structured clone algorithm copies supported data, but it does not preserve arbitrary object behavior or every property detail.
- Class behavior: The original prototype chain is not cloned, so a class instance does not return as an instance with its original methods. Private class elements are not preserved.
- Property details: Property descriptors and accessors—including getters and setters—are not preserved.
- Unsupported values: Functions and DOM nodes cannot be cloned and cause a
DataCloneError.
If a copy must retain a class’s invariants or methods, use an explicit constructor or factory, or implement a domain-specific clone method. Reconstructing the instance makes the intended behavior explicit rather than relying on a generic data-copy operation.
Choose the cloning approach that fits the data
| Approach | Use it when | Main limitation |
|---|---|---|
structuredClone(value) |
The value is structured-cloneable and the runtime provides the API. | It supports cycles and many built-ins, but does not retain functions, DOM nodes, custom prototype behavior, property descriptors, or private fields. |
JSON.parse(JSON.stringify(value)) |
The data is deliberately limited to JSON-serializable values. | JSON serialization cannot represent all JavaScript values or object details, so the round trip can omit information. |
| Explicit reconstruction or a type-specific clone method | Class identity, invariants, or custom semantics must be retained. | You must define the correct copying behavior for the types in your application. |
When JSON serialization is enough
For data intentionally restricted to JSON, a stringify/parse round trip can make a deep copy:
const copy = JSON.parse(JSON.stringify(value));
Do not treat this as a general-purpose clone. JSON serialization may omit properties or other aspects of the source; use it only when the data shape and those losses are acceptable. MDN explains the limits of serializable objects and the meaning of a deep copy.
Check TypeScript declarations and runtime support
If TypeScript reports that structuredClone is unknown, check the built-in declarations available to the project. TypeScript’s declarations depend on configuration such as target, and the lib option controls which built-in APIs TypeScript knows about. The TypeScript Handbook explains type declarations and library declaration structures.
Best Value
Then check the actual JavaScript runtime where the code will run. A TypeScript declaration only affects type checking; it does not add or polyfill a missing runtime API. Verify support for your target environment rather than relying on a declaration alone.
Copying versus transferring
structuredClone() also accepts a transfer option for transferable resources. A transfer is not an ordinary copy: the resource moves to the clone and becomes unusable on the original. Use it only when that change to the original is intended; otherwise, clone without transferring.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

