Skip to main content
updated to remove extraneous specificity
Source Link
Brian Henry
  • 3.2k
  • 1
  • 19
  • 17

This is horribly unreadable, so I apologize for that.

But you could try this:

var v = {pt:new Array()}; for(var a in data) eval("if(!v." + /pt\[\d+\]/.exec(a) + ") v." + /pt\[\d+\]/.exec(a) + " = {x:null,y:null,z:null,selid:null}; v." + a.replace(/\]\[/,"][\"").replace(/\]$/,"\"]") + " = " + data[a]); 

then v should have what you want.

(it's just creating/executing the following lines of code:

if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["y"] = 1.3571934700012207 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["selid"] = 2 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["z"] = 0 if(!v.pt[3]) v.pt[3] = {x:null,y:null,z:null,selid:null}; v.pt[3]["x"] = 3.6684491634368896 if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["z"] = 0 

)

This is horribly unreadable, so I apologize for that.

But you could try this:

var v = {pt:new Array()}; for(var a in data) eval("if(!v." + /pt\[\d+\]/.exec(a) + ") v." + /pt\[\d+\]/.exec(a) + " = {x:null,y:null,z:null,selid:null}; v." + a.replace(/\]\[/,"][\"").replace(/\]$/,"\"]") + " = " + data[a]); 

then v should have what you want.

(it's just creating/executing the following lines of code:

if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["y"] = 1.3571934700012207 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["selid"] = 2 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["z"] = 0 if(!v.pt[3]) v.pt[3] = {x:null,y:null,z:null,selid:null}; v.pt[3]["x"] = 3.6684491634368896 if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["z"] = 0 

)

This is horribly unreadable, so I apologize for that.

But you could try this:

var v = {pt:new Array()}; for(var a in data) eval("if(!v." + /pt\[\d+\]/.exec(a) + ") v." + /pt\[\d+\]/.exec(a) + " = {}; v." + a.replace(/\]\[/,"][\"").replace(/\]$/,"\"]") + " = " + data[a]); 

then v should have what you want.

(it's just creating/executing the following lines of code:

if(!v.pt[2]) v.pt[2] = {}; v.pt[2]["y"] = 1.3571934700012207 if(!v.pt[0]) v.pt[0] = {}; v.pt[0]["selid"] = 2 if(!v.pt[0]) v.pt[0] = {}; v.pt[0]["z"] = 0 if(!v.pt[3]) v.pt[3] = {}; v.pt[3]["x"] = 3.6684491634368896 if(!v.pt[2]) v.pt[2] = {}; v.pt[2]["z"] = 0 

)

Source Link
Brian Henry
  • 3.2k
  • 1
  • 19
  • 17

This is horribly unreadable, so I apologize for that.

But you could try this:

var v = {pt:new Array()}; for(var a in data) eval("if(!v." + /pt\[\d+\]/.exec(a) + ") v." + /pt\[\d+\]/.exec(a) + " = {x:null,y:null,z:null,selid:null}; v." + a.replace(/\]\[/,"][\"").replace(/\]$/,"\"]") + " = " + data[a]); 

then v should have what you want.

(it's just creating/executing the following lines of code:

if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["y"] = 1.3571934700012207 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["selid"] = 2 if(!v.pt[0]) v.pt[0] = {x:null,y:null,z:null,selid:null}; v.pt[0]["z"] = 0 if(!v.pt[3]) v.pt[3] = {x:null,y:null,z:null,selid:null}; v.pt[3]["x"] = 3.6684491634368896 if(!v.pt[2]) v.pt[2] = {x:null,y:null,z:null,selid:null}; v.pt[2]["z"] = 0 

)