Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides 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

Use structuredClone(value) to deep-copy supported JavaScript data in memory; use JSON.stringify(value) when you need JSON text for storage or exchange. The common JSON.parse(JSON.stringify(value)) workaround is not a general-purpose clone: it loses or changes some values and fails on circular references.

Choose by what you need the result to do

Your goal or data Better fit Reason
Deep-copy supported in-memory data, including circular references structuredClone() It tracks references and can reproduce cycles in the cloned data.
Preserve supported types such as Date, Map, or Set structuredClone() These types are supported by the structured clone algorithm.
Produce JSON text for storage or interchange JSON.stringify() It converts a value into JSON notation.
Clone functions, DOM nodes, or custom object behavior faithfully Neither is a drop-in solution Structured cloning rejects some values and discards some object semantics; JSON omits or converts values it cannot represent.
Transfer ownership of supported transferable data structuredClone(value, { transfer }) Transfer changes ownership: the original transferred object is no longer usable.

If a specific older browser, embedded web view, or runtime is a requirement, verify support in that target rather than relying only on current-engine version thresholds.

What structuredClone() copies—and what it does not

structuredClone(value) uses the structured clone algorithm to create a deep copy of supported values. It handles circular references and commonly used built-in types such as Date, Map, Set, ArrayBuffer, DataView, and typed arrays. See the MDN guide to the structured clone algorithm and the WHATWG HTML Standard’s structured data section.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Unsupported values and lost semantics

  • Functions and DOM nodes cannot be cloned; attempting to clone them causes a DataCloneError.
  • Custom prototypes are not walked or duplicated. A clone should not be assumed to retain a custom class’s prototype behavior.
  • Property descriptors, getters, and setters are not copied as such.
  • A regular expression’s lastIndex value is not preserved.

So “deep copy” does not mean “recreate every detail of every JavaScript object.” If code depends on custom methods, accessors, or other object-specific behavior, choose or implement a clone strategy that explicitly accounts for those requirements.

Transfer is not an ordinary copy

The optional transfer setting lets you transfer supported transferable objects instead of copying them. Once transferred, the original object is no longer usable. This is an ownership change, not merely a faster way to make a copy; use it only when the source should relinquish access. The HTML Standard describes the transfer behavior.

Check support in your deployment targets

The current HTML Standard index lists reference thresholds of Chrome 98+, Firefox 94+, Safari 15.4+, and Edge 98+. These are not a guarantee for every runtime, embedded web view, or deployment configuration. Check the actual environments your application supports against the HTML Standard index.

What JSON.stringify() does to JavaScript values

JSON.stringify(value) converts a value into JSON text. That makes it appropriate when the output itself needs to be JSON—for example, for storage or interchange—not as a universal in-memory cloning mechanism. The MDN reference for JSON.stringify() documents its conversion rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • undefined, functions, and symbols used as object-property values are omitted from the output.
  • The same values in arrays become null.
  • Serializing a BigInt throws unless custom serialization behavior is supplied.
  • Circular references cause a TypeError, because JSON does not represent object-reference cycles.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why stringify-then-parse is not a general deep clone

JSON.parse(JSON.stringify(value)) first converts the input to JSON text, then builds a new value from that text. The resulting value can contain only what the JSON conversion retained. Omitted properties stay omitted, converted array entries stay converted, and a circular reference prevents serialization altogether.

Use this pattern only when the input is intentionally limited to data that survives JSON conversion and a JSON-shaped result is acceptable. If you need to preserve supported JavaScript types or cycles in a deep copy, prefer structuredClone(); if you need JSON text, call JSON.stringify() directly. MDN also advises considering structuredClone() when stringify is being used for deep copying, while documenting structured cloning’s own limits.