DeepCopy in Javascript
Sometimes you need to perform a deep copy in Javascript.
Spread obviously doesn’t work, since it does a shallow copy.
I’ve used JSON.parse(JSON.stringify)
, but that doesn’t work with Date
or other
data structures, like Map
and Set
and others.
But recently I’ve came across the structuredClone
which does what’s expected.
And the support seems okay, although
core-js
has a polyfill.
For the full list of supported types, see the MDN docs.