I have a json that returns an array with a date and measurements. Within the measures there are values that I want to consolidate, after ordering the data by month.
obj {
0:{
'timestamp': "2016-01-02T08:13:00+00:00",
'measure':{
'calories': {
'text': 'cals',
'unit': 10
},
'steps': {
'text': 'm',
'unit': 10
}
}
},
1:{
'timestamp': "2016-01-03T08:13:00+00:00",
'measure':{
'calories': {
'text': 'cals',
'unit': 30
},
'steps': {
'text': 'm',
'unit': 30
}
}
},
3:{
'timestamp': "2015-12-31T08:13:00+00:00",
'measure':{
'calories': {
'text': 'cals',
'unit': 15
},
'steps': {
'text': 'm',
'unit': 15
}
}
},
4:{
'timestamp': "2015-12-31T08:13:00+00:00",
'measure':{
'calories': {
'text': 'cals',
'unit': 40
},
'steps': {
'text': 'm',
'unit': 40
}
}
},
}
Basically this is the array with the objects that it returns to me, with momentJS I formatted the year and managed to filter by month, but I have not achieved any way to group and add the measure of each month, taking into account that every month has its days
expected result
{
'timestamp': '2016'
'month': 'jan',
'measure':{
'calories': {
'text': 'cals',
'unit': 20 // valor consolidado de cada dia
},
'steps': {
'text': 'm',
'unit': 20 // valor consolidado de cada dia
}
},
'timestamp': '2015'
'month': 'dec',
'measure':{
'calories': {
'text': 'cals',
'unit': 20 // valor consolidado de cada dia
},
'steps': {
'text': 'm',
'unit': 20 // valor consolidado de cada dia
}
}
What methods could I use to solve it, I have tried with lodash but without achieving full results