Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/ext/web/lib.deno_web.d.ts>structuredClone

A modern runtime for JavaScript and TypeScript.
Latest
function structuredClone
import { structuredClone } from "https://deno.land/x/deno@v2.0.4/ext/web/lib.deno_web.d.ts";

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

Unlike a shallow copy, a deep copy does not hold the same references as the source object, meaning its properties can be changed without affecting the source. For more details, see MDN.

Throws a DataCloneError if any part of the input value is not serializable.

Examples

Example 1

const object = { x: 0, y: 1 };

const deepCopy = structuredClone(object);
deepCopy.x = 1;
console.log(deepCopy.x, object.x); // 1 0

const shallowCopy = object;
shallowCopy.x = 1;
// shallowCopy.x is pointing to the same location in memory as object.x
console.log(shallowCopy.x, object.x); // 1 1

Type Parameters

optional
T = any