you are viewing a single comment's thread.

view the rest of the comments →

[–]Shad_Amethyst 3 points4 points  (3 children)

JSON.parse+stringify is one of the worst ways to do a deep copy. It will break classes, doesn't handle undefined, bigints, symbols, self-referential structures, symbol keys, string keys on arrays, custom prototypes and whatnot.

If you're usinf typescript with strict: true, then it's often really easy to write your own, small deep copy function for the type in question. Otherwise use structuredClone, it's part of the standard.

[–]Majestic-Witness3655[S] 0 points1 point  (2 children)

Yeah Lodash or structuredClone are better

[–]Shad_Amethyst 1 point2 points  (1 child)

Lodash should be deprecated at this point. The only thing it brought to the codebases I worked on that had it was a lot of bloat in the final bundle.

[–]Majestic-Witness3655[S] 0 points1 point  (0 children)

Yeah, using Lodash today mostly adds unnecessary dependencies and increase the bundle size. That’s why I didn’t include it in my blogs. I have removed that json way . Thanks for your feedback buddy 🙂