Deep-copying in JavaScript using structuredClone

No more hacking around with the inadequate JSON.parse() or bouncing data to a Web Worker in order to deep clone an object, as there’s now structuredClone()

For the longest time, you had to resort to workarounds and libraries to create a deep copy of a JavaScript value. The Platform now ships with structuredClone(), a built-in function for deep-copying.

Like so:

const myDeepCopy = structuredClone(myOriginal);

If I recall correctly, Deno was the first to support this. Also available in Node 17 and Firefox. Safari has it feature-flagged, but it’s expected soon. Will ship with Chromium 98 (currently in beta).

Deep-copying in JavaScript using structuredClone

Published by Bramus!

Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google. From the moment he discovered view-source at the age of 14 (way back in 1997), he fell in love with the web and has been tinkering with it ever since (more …)

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.