My JSON looks like this:
json = [
{
type: \"big\"
date: \"2012-12-08\"
qty: 6
}
{
type: \"small\"
date: \"2012-12-08\"
qty: 9
}
Alternative solution:
var result = [];
$(json).each(function (i, e){
var search = $.grep(result, function(elm){ return e.type == elm.type && e.date.substring(0, 7) == elm.date; });
if(search.length == 0)
result.push({ type: e.type, date: e.date.substring(0, 7), qty: e.qty });
else
search[0].qty += e.qty;
});