The below function returns chart data 

The output returned by the above function is in the below format

```
[Object { date=Date,  value=112,  volume=1469}, Object { date=Date,  value=124,  volume=539}, Object { date=Date,  value=114,  volume=859}, Object { date=Date,  value=123,  volume=1284}, Object { date=Date,  value=113,  volume=1382}, Object { date=Date,  value=129,  volume=1353}]

```

From the output generated by `getChartData` above, I'm eager to see an output of the below kind where01,02 etc are the month numbers. This is basically aggregating data to the day of week level per month.

```
[{'dayofweek':'01-SUN','value':xxx,'volume':'yyy},{'dayofweek':'01-MON','value':xxx,'volume':'yyy},{'dayofweek':'01-TUE','value':xxx,'volume':'yyy},{'dayofweek':'01-WED','value':xxx,'volume':'yyy},{'dayofweek':'01-THU','value':xxx,'volume':'yyy},{'dayofweek':'01-FRI','value':xxx,'volume':'yyy},{'dayofweek':'01-SAT','value':xxx,'volume':'yyy}]

```

I were to `JSON.stringify` the output of `getChartData` the array, the output looks as below ( Showing this so that the value of `'date'` field is visible

```
[{"date":"2014-10-06T06:00:00.000Z","value":119,"volume":1417},{"date":"2014-10-07T06:00:00.000Z","value":126,"volume":1421},{"date":"2014-10-08T06:00:00.000Z","value":140,"volume":850}]

```

The above array has several hundred objects. I'm trying to aggregate this to achieve the sum of `value` & `volume` fields month by month at a day of the week level ( Total for Sunday, Monday etc .... Sat).

The object array can have any field. I mean, I'd like to write a dynamic function where the first element of every object will be a date field denoted by any variable name (date, xdate,ydate whatever). The rest of the fields apart from the first field(In sometimes there may be 2 fields, 3 fields or 'n' number of fields) needs to be added up & aggregated to day of week level per month

Here is what I'm doing

```
function setGroupingDayOfWeek(thisObj) {
  var chartData = getChartData("chartdiv");
  var keysOnly = Object.keys(chartData[0]);
  var objStruct = getObjStruct(keysOnly);
  var chartFeedJson = updatejsonStruct(objStruct,chartData)
}

function getObjStruct(keyArray) {
    //  var arrToObjContent = _.values(Object.keys(jsonData[0])),
  var arrToObjContent = keyArray,
    dayOfWeek = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"],
    i = 0,
    z,
    arrToObjLength = arrToObjContent.length,
    dayOfWeekLength = dayOfWeek.length,
    jsonObj = {},
    newObj,
    key,
    value;

  for (; i < dayOfWeekLength; i++) {
    newObj = {};
    for (z = 0; z < arrToObjLength; z++) {
      key = arrToObjContent[z];

      if (key === arrToObjContent[0]) {
        value = dayOfWeek[i];
      } else {
        value = "";
      }
      newObj[key] = value;
    }
    jsonObj[i] = newObj;
  }
  return jsonObj;
}

function updatejsonStruct(objStruct,chartData) {
    var baseStruct = objStruct,
        chartDataFormatted = JSON.stringify(chartData);
// The idea here is to first group it by months & then loop through & sum up all Sundays, Mondays etc to the end of week
    var groupedByMonth = _.groupBy(chartDataFormatted , function (item) {
        return item[0].substring(0, 9);
    });     
    console.log(groupedByMonth);
}

```

This isn't grouping data by months. obviously, I'm doing the wrong thing in the aggregation. A few questions with regards to this -

1) how could I use `chartData` which is the non-strigified version & group it by months

2) if (1) is hard/complex, how could I use `chartDataFormatted` to do the grouping by months

3) At the end of this, I'd like to update the `objStruct` with the details of the calculation ( Grouping by days ogf the week)

Now, this is entirely what I thought of doing as I don't have good experience with Jquery or other cool javacript libraries. If there is a better of doing this (Say without the need of `baseStruct` or directly aggregating data into the needed format), I'm excited to get some guidance. 

If I've missed explaining something you think is needed or if I've not communicated clearly, please let me know. I'll try my best to clarify. I've been stuck with this with no much ideas. Hence, requesting help please.

**Trying to reduce grouping to Just Mon through to Sat -**

Obviously I'm not accessing the object array in the right way. The idea is to create a master array having Mon - Sun as one of the many fields in an object array containing 7 objects ( One object for each day of the week). The final object array should have just 7 objects one per day of the week.

How exactly can I look up the obejct array & check the value of zeroth field within it?

```
var days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
var chartData = getChartData("chartdiv");

//use var chartData = getChartData("chartdiv") here instead;
keys = Object.keys(chartData[0]);
var newObjStruct = [{},{},{},{},{},{},{}];

for(var k = 0; k < days.length; k++){
  for(var i = 0; i < keys.length; i++){
      if (i === 0) {
          newObjStruct[k]['dayOfWeek' ] = days[k];
      } else {
          newObjStruct[k][keys[i]] = "";          
  }
  }
}

console.log(newObjStruct);

for (j=0; j<chartData.length; j++){
var castObj = JSON.stringify(chartData[j]);
console.log(castObj[0]);
//val.date.getDay();
      for(k = 0; k < newObjStruct.length; k++) {
           if (newObjStruct[k][0] === days[day]) {
for(var i = 0; i < keys.length; i++){
              newObjStruct[k][i] += chartData[keys[i]];
          } 
           }          
  }
}

```