CKTIS / JavaScript
Structured clone algorithm and transferable ownership
structuredClone() copies supported data structures while preserving cycles and repeated references within the copy. The transfer option moves resources instead of copying them and detaches the original ArrayBuffer.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
structuredClone(value)
structuredClone(value, { transfer: [buffer] })structuredClone(value) clones supported data. The algorithm remembers visited objects: it preserves cycles and shared references within the result, but cloned objects have different identities from their originals. postMessage() and IndexedDB also use this algorithm.
A distinct object does not always mean independent memory. Cloning an ordinary ArrayBuffer without transfer creates an independent copy of its bytes, as the example shows. Where cloning a SharedArrayBuffer is permitted, the clone is a distinct buffer object that shares the same backing memory as the original.
Supported types include plain objects, arrays, Map, Set, Date, ArrayBuffer, and typed arrays. Functions, DOM nodes, and symbol values cannot be cloned; an unsupported value in the data causes DataCloneError. The algorithm does not preserve custom prototype chains, property descriptors, getters/setters, or class private elements. It is therefore not a universal way to copy class instances.
structuredClone(value, { transfer: [buffer] }) transfers ownership of a resource instead of copying its bytes. The source ArrayBuffer becomes detached: its byteLength is 0, and existing views no longer provide access to the data. A Uint8Array is cloneable, but you transfer its buffer, not the view itself. An ArrayBuffer listed in transfer can be detached even if it is not reachable from value. In that case, it will not appear in the returned clone. Transfer does not require a worker.
This is a host API defined by the HTML standard, not a feature of a particular ECMAScript edition. MDN reports broad browser availability since March 2022; check the target environment with typeof structuredClone === "function". Node 24 in a repository does not prove browser support. The example compares copying with transfer and checks preservation of a cycle and an alias.
Reference identifiers covered by this entry: Structured clone algorithm and transferable ownership.
Examples
const bytes = new Uint8Array([7, 8]);
const original = { bytes, alias: bytes };
original.self = original;
const copy = structuredClone(original);
copy.bytes[0] = 9;
console.log(copy !== original, copy.self === copy, copy.bytes === copy.alias);
console.log(original.bytes[0], copy.bytes[0]);
const moved = structuredClone(original, { transfer: [bytes.buffer] });
console.log(bytes.buffer.byteLength, moved.bytes.byteLength);
console.log(moved.bytes[0], moved.self === moved, moved.bytes === moved.alias);Result
true true true 7 9 0 2 7 true true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.