I was wondering how can I create a JSON (JS) object and then clone it.
By using both, we first make a JSON string from the object we want to copy ( JSON. stringify(objectToCopy) ). Then, we take that JSON string and make a new object from it (with JSON. parse() ).
This is what I do and it works like a charm
if (typeof JSON.clone !== "function") { JSON.clone = function(obj) { return JSON.parse(JSON.stringify(obj)); }; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With