title: Counting json array objects and create a new array with SUM result
body: <p>I have a JSON array like this and,</p>
  <pre><code>const arrayVal = [{
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;JAKE&quot;,
      &quot;TEAM_NO&quot;: 2,
      
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;ANNA&quot;,
      &quot;TEAM_NO&quot;: 2,
      
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;JEFF&quot;,
      &quot;TEAM_NO&quot;: 1,
      
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;ERIKA&quot;,
      &quot;TEAM_NO&quot;: 2,
     
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;SUTTON&quot;,
      &quot;TEAM_NO&quot;: 3,
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;NAME&quot;: &quot;ARNOLD&quot;,
      &quot;TEAM_NO&quot;: 3,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;JAKE&quot;,
      &quot;TEAM_NO&quot;: 4,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;ANNA&quot;,
      &quot;TEAM_NO&quot;: 2,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;JEFF&quot;,
      &quot;TEAM_NO&quot;: 1,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;ERIKA&quot;,
      &quot;TEAM_NO&quot;: 3,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;SUTTON&quot;,
      &quot;TEAM_NO&quot;: 5,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;NAME&quot;: &quot;ARNOLD&quot;,
      &quot;TEAM_NO&quot;: 5,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;JAKE&quot;,
      &quot;TEAM_NO&quot;: 1,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;ANNA&quot;,
      &quot;TEAM_NO&quot;: 1,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;JEFF&quot;,
      &quot;TEAM_NO&quot;: 1,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;ERIKA&quot;,
      &quot;TEAM_NO&quot;: 2,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;SUTTON&quot;,
      &quot;TEAM_NO&quot;: 3,
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-3&quot;,
      &quot;NAME&quot;: &quot;ARNOLD&quot;,
      &quot;TEAM_NO&quot;: 3,
        
  }];
  </code></pre>
  <p>I am just trying to get below kind of reult out of above array. In this I want to count team numbers by day and create a new array with &quot;TEAM_NO_COUNT&quot; parameter.</p>
  <pre><code>[{
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;TEAM_NO&quot;: 3, 
      &quot;TEAM_NO_COUNT&quot;: 2, // 2 entries with no 3 team
       
  }, {
      &quot;DATE&quot;: &quot;2020-12-1&quot;,
      &quot;TEAM_NO&quot;: 1,
      &quot;TEAM_NO_COUNT&quot;: 2,  // 2 entries with no 1 team
  }, {
      &quot;DATE&quot;: &quot;2020-12-2&quot;,
      &quot;TEAM_NO&quot;: 4,
      &quot;TEAM_NO_COUNT&quot;: 1,  
  }]
  </code></pre>
  <p>I have this code so far but it just give me a json object with counted team numbers, But It is not I want, I need above exact result.</p>
  <pre><code>TEAM_NO_COUNT = {}; // create an object
  $.each(JSON.parse(JSON.stringify(arrayVal)), function (key, val) {
  
  DATE_NO_CO = {};
  
    TEAM_NO_COUNT[val.DATE] = (TEAM_NO_COUNT[val.DATE] || {});
  
    TEAM_NO_COUNT[val.DATE][val.TEAM_NO] = (TEAM_NO_COUNT[val.DATE][val.TEAM_NO] || 0) + 1;
    
  });
  
  alert(JSON.stringify(TEAM_NO_COUNT));
  </code></pre>
  <p>Could someone please give me a help. It would be highly appreciated. Thanks.</p>