Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get an array out of a javascript proxy

I was wondering how to get an array out of a proxy's target value in JavaScript. I have something like this :

Proxy :
  [[target]] : Array // the array I need to extract
  [[handler]] : Object 
  [[IsRevoked]] : false
like image 253
Jip Helsen Avatar asked Sep 11 '25 02:09

Jip Helsen


2 Answers

Just take that original object and parse it to and from JSON and get yourself a clean object!

item = JSON.parse(JSON.stringify(item))
like image 140
Pinch Avatar answered Sep 13 '25 16:09

Pinch


If all you have is a reference to the proxy, there is no way (by default) for you to get the proxy's target. A specific proxy could provide a way (via one of its trap handlers, probably), but there is none by default.

like image 44
T.J. Crowder Avatar answered Sep 13 '25 15:09

T.J. Crowder