structuredClone()

Creates a deep copy of a value using the structured clone algorithm.

Since ES2015 (ES6) Spec ↗

Syntax

structuredClone(value, options)

Returns

any — A deep clone of `value`.

Throws

  • DataCloneError — The value contains something non-cloneable, such as a function or DOM node.

Examples

const original = { a: 1, nested: { b: 2 } };
const copy = structuredClone(original);
copy.nested.b = 99;
console.log(original.nested.b, copy.nested.b);
Output
2 99
const arr = [new Date(0), new Map([["k", 1]])];
const clone = structuredClone(arr);
console.log(clone[0].getTime(), clone[1].get("k"));
Output
0 1

Notes

- Handles circular references and many built-in types (Map, Set, Date, ArrayBuffer, typed arrays). - Cannot clone functions, DOM nodes, or property descriptors/getters. - Available in browsers and Node.js 17+.

Browser & runtime support

EnvironmentSince version
chrome 98
firefox 94
safari 15.4
edge 98
node 17.0