I have a data like this:
var dates = [
{date: "2000-01-01", total: 120},
{date: "2000-10-10", total: 100},
{date: "2010-02-08", total: 100},
{date: "2010-02-09", total: 300}
];
I want to create a grouped and sum of total like this.
var grouped = [
{date: "2000", total: 220},
{date: "2010", total: 100}
];
I am using underscorejs but did not find function.
var byYear = _.map(dates, function(item){
var year = new Date(Date.parse(item.date)).getFullYear();
return {date: year, total: item.total};
});
workig code is here.