Deep Copy a JavaScript Object: structuredClone vs JSON vs Spread
To deep copy a JavaScript object, use structuredClone(obj). It's built into every current browser and into Node.js since v17, it copies nested objects, Dates, Maps, Sets and circular references correctly, and it throws a clear error when it meets something it can't copy. The old …