I have the following code:
Arr = ["meu", "objeto", "dinamico"];
Val = 100;
Eval = "";
obj = {};
for(i in Arr){
Eval += "['"+ Arr[i] + "']";
eval("obj"+Eval+"={}")
}
eval("obj"+Eval+"="+Val);
As you can see, this code dynamically generates the obj.meu.objeto.dinamico
property and adds the value of Val
to it, however this code is somewhat ridiculous, I tried to make the same code without using eval()
, but I can not imagine a decent solution.