rearrange javascript object
<p>I have an object with depth at most 3:</p>

<pre><code>OBJ.T.V.E={...}
</code></pre>

<p>T and V are integers (like in OBJ[0][1]['String']={...} )
so a typical structure could be:</p>

<pre><code>OBJ[0][0]['S1']={..}
OBJ[0][0]['S2']={..}
OBJ[0][1]['S1']={..}
OBJ[0][2]['S1']={..}
</code></pre>

<p>I want to rearrange and get somehow this:</p>

<pre><code>OBJNEW['S1'][0][0]={...}
</code></pre>

<p>which would have the same value as in <code>OBJ[0][0]['S1']</code></p>

<p>I'm struggling for hours with no luck. Any ideas? Jquery code is also welcome.</p>

<p><strong>EDIT</strong>:
Right now I tried creating an array of objects like that:</p>

<pre><code>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']={};
    })
  })
</code></pre>

<p>But this step fails since each ...['S1'] assignment overwrites the previous object (e.g. S2).</p>

<p>Please ignore any typos, I have just recreated the logic.</p>
