title: using reduce function on list of objects javascript
body: <p>I have number of objects im receiving weekly, each one on these object has date, hours, and other fields. I wanna sort these object array  total hours of each day.</p>
  
  <p>example of the objects</p>
  
  <pre><code>var anArray = [{
    'End':"22:00",
    'Id':"Q45575",
    'Name':"W-299849",
    'Start':"20:00",
    'date':"2018-02-04",
    'hours':2
  },{
    'End':"21:00",
    'Id':"Q45551",
    'Name':"W-299809",
    'Start':"15:00",
    'date':"2018-02-07",
    'hours':5
  },{
    'End':"20:00",
    'Id':"Q45515",
    'Name':"W-299849",
    'Start':"10:00",
    'date':"2018-02-04",
    'hours':2
  }];
  </code></pre>
  
  <p>output should be like this, assuming sunday is 2/4</p>
  
  <p>Sun Mon tue Wed fri sat</p>
  
  <p>4 0 0 5 0 0 </p>
  
  <p>This what I have</p>
  
  <pre><code>  var resourceData = data.reduce((a, c) =&gt; {
    var targetDay = new Date(c.date).getDay() === 6 ? 0 : (new Date(c.date).getDay() + 1);
    if (a) {
      a['week'][targetDay] += c.hours;
    } else {
      a = { 'week': new Array(7).fill(0) };
      a['week'][targetDay] = c.hours;
    }
    return a;
  }, {});
  </code></pre>
  
  <p>is not working im getting error with targetDay </p>