Recommended Free Tools
For ordinary data supported by JavaScript’s structured clone algorithm, use structuredClone(value):
const copy = structuredClone(value);
It makes a deep copy of supported values, including nested objects, arrays and circular references. It does not preserve arbitrary class behavior, and the JavaScript runtime—not TypeScript alone—must provide the API. MDN documents structuredClone().
As an Amazon Associate I earn from qualifying purchases.
Clone nested objects with structuredClone()
A deep clone gives nested data independent references, so changing a nested object in the copy does not change the corresponding object in the original:
const original = {
user: { name: "Ada" },
tags: ["typescript", "javascript"],
};
const copy = structuredClone(original);
copy.user.name = "Grace";
// original.user.name remains "Ada"
This is suitable when the value consists of types supported by the structured clone algorithm. It is the simplest general-purpose choice for such data.
#1 Best Overall
What structuredClone() can and cannot clone
Supported values include plain objects, arrays, dates, maps, sets, array buffers, data views, typed arrays, regular expressions, errors and primitive values other than symbols. Support for a type does not mean every aspect of its behavior or metadata is preserved. See MDN’s structured clone algorithm reference and its overview of serializable objects.
- Functions and DOM nodes: these cannot be cloned; attempting to clone unsupported values can throw a
DataCloneError. - Class instances: the prototype chain is not cloned, so the result does not retain the original class’s methods or identity. Private class elements are not preserved.
- Property details: property descriptors and accessor behavior, including getters and setters, are not preserved.
If your code depends on a class’s invariants or methods, rebuild the value through its constructor or factory, or implement a clone method that captures the intended domain-specific behavior. A generic deep-clone API cannot infer those rules.
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
Circular references are supported
A self-reference does not make structuredClone() recurse forever. The algorithm tracks references it has already visited, allowing the copied graph to reproduce cycles:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
const original: { label: string; self?: unknown } = { label: "node" };
original.self = original;
const copy = structuredClone(original);
// copy.self points back to copy.
Choose a cloning approach for your data
| Approach | Use it when | Tradeoff |
|---|---|---|
structuredClone(value) |
Your value is structured-cloneable and the runtime provides the API. | Supports cycles and many built-in types, but does not preserve functions, DOM nodes, custom prototype behavior, descriptors or private fields. MDN |
JSON.parse(JSON.stringify(value)) |
Your data is deliberately limited to JSON-serializable values. | JSON serialization does not represent every JavaScript value or object property, so information can be omitted. MDN’s deep-copy overview |
| Explicit reconstruction or a type-specific clone method | The copy must retain class identity, invariants or custom semantics. | You must define which state and behavior the new instance should preserve. |
The JSON round trip is a constrained option, not a universal deep-clone technique:
const copy = JSON.parse(JSON.stringify(value));
Check both TypeScript declarations and runtime support
If TypeScript reports that structuredClone is unknown, check the built-in library declarations selected by your project’s target and lib settings. TypeScript explains how its declarations are selected in the Type Declarations handbook and the Library Structures reference.
Then verify that the JavaScript runtime where the code will execute supports structuredClone(). A TypeScript declaration only tells the compiler about an API; it does not install or polyfill that API. Check the compatibility information for your specific browser, server runtime or deployment target rather than assuming one minimum version applies everywhere.
Copying is not the same as transferring
structuredClone() also accepts a transfer option for transferable resources. Transferring moves the resource to the clone; the original resource becomes unusable. Use that option only when moving ownership is intended, not when you need to keep using both the original and the copy. MDN’s method reference describes the option.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsQuick Recap
Best Value
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.




