Deep Clone with Structured Clone API
By xyz on 2 weeks ago|0 comment||
0
The structuredClone API provides a simpler and more reliable way to clone objects deeply. Unlike the JSON.parse(JSON.stringify(obj)) method, it can handle more complex data types like Map, Set, and Date, which are lost with the former approach. This method ensures that all nested structures are accurately duplicated without side effects.
const obj = { name: "John", nested: { age: 30 }};
const clone = structuredClone(obj);
Add a Comment
Comments
Comments MIA, jokes needed ASAP. Add yours! 😄