Deep-copying in JavaScript using structuredClone

No more hacking around with the inadequate JSON.parse() or bouncing data to a Web Worker in order to deep clone an object, as there’s now structuredClone() For the longest time, you had to resort to workarounds and libraries to create a deep copy of a JavaScript value. The Platform now ships with structuredClone(), a built-in …


This content originally appeared on Bram.us and was authored by Bramus!

No more hacking around with the inadequate JSON.parse() or bouncing data to a Web Worker in order to deep clone an object, as there’s now structuredClone()

For the longest time, you had to resort to workarounds and libraries to create a deep copy of a JavaScript value. The Platform now ships with structuredClone(), a built-in function for deep-copying.

Like so:

const myDeepCopy = structuredClone(myOriginal);

If I recall correctly, Deno was the first to support this. Also available in Node 17 and Firefox. Safari has it feature-flagged, but it’s expected soon. Will ship with Chromium 98 (currently in beta).

Deep-copying in JavaScript using structuredClone


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2021-12-21T00:05:34+00:00) Deep-copying in JavaScript using structuredClone. Retrieved from https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/

MLA
" » Deep-copying in JavaScript using structuredClone." Bramus! | Sciencx - Tuesday December 21, 2021, https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/
HARVARD
Bramus! | Sciencx Tuesday December 21, 2021 » Deep-copying in JavaScript using structuredClone., viewed ,<https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/>
VANCOUVER
Bramus! | Sciencx - » Deep-copying in JavaScript using structuredClone. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/
CHICAGO
" » Deep-copying in JavaScript using structuredClone." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/
IEEE
" » Deep-copying in JavaScript using structuredClone." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/. [Accessed: ]
rf:citation
» Deep-copying in JavaScript using structuredClone | Bramus! | Sciencx | https://www.scien.cx/2021/12/21/deep-copying-in-javascript-using-structuredclone-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.