title: How to pivot a javascript array
body: <p>I have this javascript array:</p>
  
  <pre><code>[['a', 'x', 1],
   ['a', 'y', 2],
   ['b', 'x', 3],
   ['b', 'z', 4],
   ['c', 'y', 5],
   ['c', 'z', 6]]
  </code></pre>
  
  <p>How do I pivot it to something like below with the 2nd column ('x', 'y', 'z') from above going across.</p>
  
  <pre><code>[['a', 1, 2, null],
   ['b', 3, null, 4],
   ['c', null, 5, 6]]
  </code></pre>
  
  <p>EDIT:
  Sorry I was unclear. The answers so far seem to be referencing a static length/value for x, y, z. The array will be dynamic and can have anything in the 2nd column (ex. 't','u','v','w' instead of 'x','y','z'). I think I need to fill the array up first with nulls for all the possible combinations and then push in the values.</p>
  
  <p>Thanks..</p>