title: Group by Id and create an array from the grouped data
body: <p>In my angular application, i am getting the response as follows.</p>
  
  <pre class="lang-js prettyprint-override"><code>[{
      "proposalId": "cc0bcd90-fc75-4c73-bd66-799b37330fb5",
      "proposalGpId": "cc0bcd90-fc75-4c73-bd66-799b37380fb5",
      "eventId": "17e69ea1-54da-11e7-9469-985aebe2005e",
      "listingId": "pdf19f7e1-5f2b-4d02-a48d-3b6d0189b5d1",
      "status": "Approved"
  }, {
      "proposalId": "cc0bcd90-fc75-4c73-bd66-799b373306b5",
      "proposalGpId": "cc0bcd90-fc75-4c73-bd66-799b37380fb5",
      "eventId": "17e69ea1-54da-11e7-9469-985aebe2005e",
      "listingId": "pdf19f7e1-5f2b-4d02-a48d-3b6d0189b5d1",
      "status": "Approved"
  }]
  </code></pre>
  
  
  
  <p>i have two classes on the application as,</p>
  
  <p><strong>ProposalGroup.ts</strong></p>
  
  <pre><code>export class ProposalGroup {
      eventId: string;
      proposalGpId: string;
      proposals: Proposal[];
  }
  </code></pre>
  
  <p><strong>Proposal.ts</strong></p>
  
  <pre><code>export class Proposal {
      proposalId: string;
      listingId: Date;
      eventId: Price;
      status: string;
  }
  </code></pre>
  
  <p>I need to create an array of ProposalGroups out of the above JSON, when to proposals have the same listingId It should be grouped. </p>
  
  <p>I want to generate an <strong><code>output</code></strong> as follows,</p>
  
  <pre class="lang-js prettyprint-override"><code>[{
      "eventId": "17e69ea1-54da-11e7-9469-985aebe2005e",
      "proposals": [{
          "proposalId": "cc0bcd90-fc75-4c73-bd66-799b37330fb5",
          "proposalGpId": "cc0bcd90-fc75-4c73-bd66-799b37380fb5",
          "eventId": "17e69ea1-54da-11e7-9469-985aebe2005e",
          "listingId": "pdf19f7e1-5f2b-4d02-a48d-3b6d0189b5d1",
          "status": "approved"
      }, {
          "proposalId": "cc0bcd90-fc75-4c73-bd66-799b373306b5",
          "proposalGpId": "cc0bcd90-fc75-4c73-bd66-799b37380fb5",
          "eventId": "17e69ea1-54da-11e7-9469-985aebe2005e",
          "listingId": "pdf19f7e1-5f2b-4d02-a48d-3b6d0189b5d1",
          "status": "approved"
      }]
  }]
  </code></pre>
  
  
  
  <p>this is what i have tried using lodash,</p>
  
  <pre><code>const grouped = _.groupBy(this.proposals, (proposal: Proposal) =&gt; proposal.listingId);
  </code></pre>
  
  <p>but the above gives a dictionary.</p>