Problem: You need to deep clone a JavaScript object


Problem: You need to deep clone a JavaScript object.

Solution: structuredClone.

It clones nearly everything including dates, array, blobs, Error, and much more.

And it's supported in all major browsers. 🔥

#javascript

More details: https://www.builder.io/blog/structured-clone
2 important caveats:

1. Users that haven't updated their browsers recently won't have this. Per caniuse, 88% of global users are running a new enough browser today. Polyfill: https://github.com/zloirock/core-js

2. There are faster options. Consider http://github.com/lukeed/klona if speed matters

View original on X