Shallow clones versus structured clones
January 14, 2025
There have been many ways in JavaScript over the years to make deep clones of objects, examples include Lodash’s cloneDeep and using JSON to stringify and then parse an object. However it turned out that the web platform already had an underlying algorithm to perform deep clones through APIs like postMessage.
In 2015 it was suggested on a W3C mailing list that the algorithm was exposed publicly, though it took until late 2021 when Deno, Node.js and Firefox released support for structuredClone, followed in 2022 by the other browsers.
If you want to make a deep clone of an object in JavaScript you should use structuredClone.
Now very widely supported, structuredClone is a standardly in JavaScript to deeply clone objects.
Here frequent speaker Phil Nash shows us how to use it.