I have an array of objects and I want to combine the objects that have the same date values so I have an array like. I am looping through them with .map(i => ) and chekcing on the previous index but i'm getting the wrong values.
[{ id: '8',
name: 'hfh',
consumed_date: '2017-03-14',
calories: 8952 },
{ id: '7',
name: 'onion',
consumed_date: '2017-03-14',
calories: 224},
{ id: '6',
name: 'onion',
consumed_date: '2017-03-14',
calories: 279},
{ id: '2',
name: 'Ready-to-Serve Chocolate Drink',
consumed_date: '2017-01-01',
calories: 3036} ]
And i want to end up with an array like
[{date: 2017-03-14,
calories: 9455},
date: 2017-01-01,
calories: 3036}]