structuredClone
Creates a deep clone of a given value using the structured clone algorithm
Syntax
structuredClone(value, options?)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | T | The value to be cloned |
| options | { transfer?: Transferable[] } | Options with transferable objects |
Return Value
A deep clone of the given value
Examples
const original = { a: 1, b: { c: 2 } };
const clone = structuredClone(original);
clone.b.c = 99;
console.log(original.b.c); // 2 (unchanged)const data = {
date: new Date(),
set: new Set([1, 2, 3]),
map: new Map([['key', 'value']]),
};
const clone = structuredClone(data);
console.log(clone.date instanceof Date); // trueconst nested = { a: [{ b: { c: [1, 2, 3] } }] };
const copy = structuredClone(nested);
copy.a[0].b.c.push(4);
console.log(nested.a[0].b.c.length); // 3 (unchanged)Understanding structuredClone
The structuredClone method in JavaScript creates a deep clone of a given value using the structured clone algorithm. It belongs to the window object and is one of the most widely used methods for working with window values in modern JavaScript and TypeScript applications.
The method signature is structuredClone(value, options?). It accepts 2 parameters: value, options. When called, it returns a deep clone of the given value. Understanding when and how to use structuredClone() helps you write more expressive, readable code.
Common use cases for structuredClone include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like object-assign, json-parse, json-stringify, enabling you to chain operations together for complex data manipulation pipelines.
Supported in Chrome 98+, Firefox 94+, Safari 15.4+, Edge 98+, and Node.js 17+.
Browser Compatibility
Supported in Chrome 98+, Firefox 94+, Safari 15.4+, Edge 98+, and Node.js 17+.
Related Methods
Object.assignCopies all enumerable own properties from one or more source objects to a target object and returns the modified target object
JSON.parseParses a JSON string, constructing the JavaScript value or object described by the string
JSON.stringifyConverts a JavaScript value to a JSON string, optionally replacing values or including only specified properties
More Global / Window Methods
Other methods in the Global / Window object
Related Tools
More Global / Window Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.