1

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?

Chuck
  • 4,662
  • 2
  • 33
  • 55
  • This proxy? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy – kelsny Nov 09 '22 at 18:01
  • You're not affecting the `event` object at all (proxy or not) when you `JSON.parse(JSON.stringify(event.detail))` you're only manipulating the `detail` property, and even that as a clone of the property stored in the `event`. – pilchard Nov 09 '22 at 18:10

0 Answers0