DEV Community

Daniel Zotti
Daniel Zotti

Posted on

3 1

#LearnedToday: structuredClone()

πŸ‘€ 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);
Enter fullscreen mode Exit fullscreen mode

πŸ—„ Docs: https://developer.mozilla.org/en-US/docs/Web/API/structuredClone

β„Ή Browser support: https://caniuse.com/?search=structuredClone

Top comments (3)

Collapse
 
tqbit profile image
tq-bit β€’

I can confidently say this is one of the most useful things I've learned this year

Collapse
 
tracygjg profile image
Tracy Gilmore β€’

Hi Daniel, I think you have a typo in the title "strucuredClone" should be "structuredClone".

Collapse
 
danielzotti profile image
Daniel Zotti β€’

Thank you so much Tracy! I fixed it :)

nextjs tutorial video

Youtube Tutorial Series πŸ“Ί

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series πŸ‘€

Watch the Youtube series