structuredClone(): The easiest way to deep copy objects in JavaScript

Tari Ibaba
Coding Beauty
Published in
3 min readMay 28, 2024

--

Deep copying is a regular programming task for passing or storing data.

  • Shallow copy: Only copies the first-level of the object
  • Deep copy: Copies all levels of the object

But all this while we’ve never had a built-in way to perfectly deep copy objects and it’s been a pain.

We always had to lean on third-party libraries for deep copying and keeping circular references.

All that changes now with the new structuredClone() — an easy and efficient way to deep copy any object.

Cloning circular references with ease:

Something you could never do with the JSON stringify/parse hack:

--

--