Reference / JavaScript
structuredClone()
Creates a deep clone of a given value using the structured clone algorithm. Supports Maps, Sets, Dates, RegExps, TypedArrays, and circular references.
Syntax
structuredClone(value: any, options?: { transfer?: Transferable[] }): anyParameters
| Name | Type | Description |
|---|---|---|
| value | any | The object to clone. |
| options | object | Optional transfer list. |
Examples
Deep cloning complex nested object
const original = { date: new Date(), map: new Map([['key', 123]]), nested: { count: 1 } };
const copy = structuredClone(original);
copy.nested.count = 99;
console.log(original.nested.count); // 1 (Unaffected)Significantly faster and more robust than JSON.parse(JSON.stringify()). Does not clone functions or DOM nodes.