I have an object with depth at most 3:
OBJ.T.V.E={...}
T and V are integers (like in OBJ[0][1][‘String’]={…} )
so a typical structure could be:
OBJ[0][0]['S1']={..}
OBJ[0][0]['S2']={..}
OBJ[0][1]['S1']={..}
OBJ[0][2]['S1']={..}
I want to rearrange and get somehow this:
OBJNEW['S1'][0][0]={...}
which would have the same value as in OBJ[0][0]['S1']
I’m struggling for hours with no luck. Any ideas? Jquery code is also welcome.
EDIT:
Right now I tried creating an array of objects like that:
OBJ2=[];
$.each(OBJ, function(name, value) {
$(value).each(OBJ, function(name1, value1) {
OBJ2[name1]=[];
$(value1).each(OBJ, function(name2, value2) {
OBJ2[name1][name2]={};
OBJ2[name1][name2]['S1']={};
})
})
But this step fails since each …[‘S1’] assignment overwrites the previous object (e.g. S2).
Please ignore any typos, I have just recreated the logic.
This should get you pretty far, unless I misunderstood.
It turns
into