I have a complicated structure shown bellow,
This structure is nested, but I need to deep-copy it. My copy function is
export function copy(o) {
if(typeof o==='object' || Array.isArray(o)) return
JSON.parse(JSON.stringify(o));
return o;
}
When I use this function to copy the structure, the error shows,
Uncaught TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at copy (util.jsx:50)
Any good ideas about how to copy nested structures? Any suggestions are welcome.