title: Group by Object ID's in Javascript
body: <p>I have an array of ID's and organizations like so:</p>
  
  <pre><code>var ids = ['1','2', '3'];
  var orgs =
      [ 
        { name: "Org 1", id: 1 },
        { name: "Org 2", id: 2 },
        { name: "Org 3", id: 2 }
      ]
  </code></pre>
  
  <p>I want to loop through these to output something like this:</p>
  
  <pre><code>{
      1: [
          {name: "Org 1", id: 1}
      ],
      2: [
          {name: "Org 2", id: 2},
          {name: "Org 3", id: 2}
      ]
  }
  </code></pre>
  
  <p>I tried this without success:</p>
  
  <pre><code>var results = orgs.forEach(function (org) {
      if (results[org.id]) {
          results.push(org)
      } else {
          results[org.id] = [org]
      };
  });
  </code></pre>