title: jQuery: how do I construct a 2d Array?
body: <p>I have this simplified version of my webpage (its a mess IRL):</p>
  
  <pre><code>&lt;li id=section1 class=sortable_section&gt;
      &lt;header&gt;
      &lt;ul id=container1&gt;
          &lt;li id=item1 class=sortable_item&gt;
          &lt;li id=item2 class=sortable_item&gt;
      &lt;/container
  &lt;/section
  
  &lt;li id=section2 class=sortable_section&gt;
      &lt;header&gt;
      &lt;ul id=container2&gt;
          &lt;li id=item3 class=sortable_item&gt;
          &lt;li id=item4 class=sortable_item&gt;
          &lt;li id=item5 class=sortable_item&gt;
      &lt;/container&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>So, I can do <code>$j("container1").sortable('serialize')</code> which creates an array of the ids of all the containing li's. so I would get <code>["item1", "item2"]</code> for <code>container1</code>.</p>
  
  <p>How do I make an array that looks like this:</p>
  
  <pre><code>[
   ["section1", ["item1", "item2"]],
   ["section2", ["item3", "item4", "item5"]]
  ]
  </code></pre>
  
  <p>This is what ive been trying: but it doesn't work</p>
  
  <pre><code>        d = $j.makeArray(
          $j('.sortable_section').each(function(i){
              [$j(this).attr("id"),
                  $j.makeArray($j.map($j("#"+$j(this).attr("id")+" .sortable_item"), function(s,j){
                      return ($j(s).attr("id"));
                  }))]
          }));
  </code></pre>
  
  <p>But it returns the entire objects, rather than just the ids....</p>
  
  <p>EDIT:
  as per one of the answers' suggestions, this is now what I have</p>
  
  <pre><code>d = $j(".sections &gt; li").map(function(index, element){
                  return [$j(element).attr('id'),
                      $j("#"+$j(element).attr('id') + " .content").map(function(subindex, subelement){
                          return $j(subelement).attr('id');
                      }).toArray()];
  
  
              }).toArray();
  </code></pre>
  
  <p>but I get this error</p>
  
  <pre><code>TypeError: Result of expression near '...}).toArray()]...' [undefined] is not a function.
  </code></pre>
  
  <p>When I do alerts on <code>$j(element).attr('id')</code> and <code>$j(subelement).attr('id')</code> I get the correct ids</p>