I'm working with events in JavaScript, and often the event is a proxy object. When debugging I can usually use this to get a copy of the object.
console.log(JSON.parse(JSON.stringify(event.detail)));
Sometimes (today, a few times), this outputs a proxy object again, but if I don't parse it, I get the raw string with the information I need:
console.log(JSON.stringify(event.detail));
Why is JSON.parse
turning a string into a proxy object? How can I get a copy of the embedded object every time?
I've found that using the spread operator can do a shallow clone of a Proxy.
let proxy = new Proxy({ foo: 1, bar: 2 }, {});
let cloned = { ... proxy };
console.log(cloned);
In your case, you could try { ... event.detail }
to get a shallow clone of the object.
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