๐ I figured out that a lot of #devs donโt know about the #standard #JavaScript method to create a #deepcopy of an object.
๐ โโ๏ธ The time of #lodash or nested #spreadoperators (or worse, JSON.parse()+JSON.stringify() is over!
๐ Now you can create a #deepclone of an object using the global method structuredClone()
. Its syntax is straightforward and it just works! Moreover, it's well supported nowadays.
const daniel = { name: "Daniel" };
const danielCloned = structuredClone(daniel);
๐ Docs: https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
โน Browser support: https://caniuse.com/?search=structuredClone
Top comments (3)
I can confidently say this is one of the most useful things I've learned this year
Hi Daniel, I think you have a typo in the title "strucuredClone" should be "structuredClone".
Thank you so much Tracy! I fixed it :)