title: Javascript push array item to named index
body: <p>I have a JSON array:</p>
  
  <blockquote>
    <p>[{   id: 1,   client: "Microsoft" },{   id: 2,   client: "Microsoft"
    },{   id: 3,   client: "Apple" }]</p>
  </blockquote>
  
  <p>and I'd like to group it by "client", but I'm having difficulty with this in javascript. In PHP i'd typically do something like this:</p>
  
  <pre><code>$group = array();
  
  foreach ($array as $item) {
  
      $group[ $item['client'] ] = $item;
  
  }
  
  return $group;
  </code></pre>
  
  <p>But this method totally wont't work in javascript on a multidimensional array</p>
  
  <pre><code>var group = [];
  
  for ( i=0 ... ) {
  
    var client = array[i].client;
  
    group[ client ].push( array[i] );
  
  }
  </code></pre>
  
  <p>How would I go about grouping the above array into something like this:</p>
  
  <blockquote>
    <p>[{ "Microsoft": [{...}], "Apple":[{...}] }]</p>
  </blockquote>
  
  <p>or even</p>
  
  <blockquote>
    <p>[{ client: "Microsoft", "items": [{...}] }, { client: "Apple", items: [{...}]  }]</p>
  </blockquote>