I imagine what you want to do is this:
var arr = [{ servicos: 0, remessa: 503, materiais: 0 , retorno: 598, entrada: 0, date: new Date("2011/12/20") },
{ servicos: 302, remessa: 0, materiais: 412 , retorno: 234, entrada: 864, date: new Date("2011/12/20") },
{ servicos: 276, remessa: 211, materiais: 0, retorno: 598, entrada: 864, date: new Date("2011/13/20") },
{ servicos: 543, remessa: 5033, materiais: 412 , retorno: 0, entrada: 864, date: new Date("2011/13/20") },
{ servicos: 876, remessa: 503, materiais: 412 , retorno: 0, entrada: 0, date: new Date("2011/13/20") }];
var result = new Object();
arr.filter(function (i){
if(result.hasOwnProperty(i.date)){
result[i.date].servicos += i.servicos;
result[i.date].remessa += i.remessa;
result[i.date].materiais += i.materiais;
result[i.date].retorno += i.retorno;
result[i.date].entrada += i.entrada;
}else{
result[i.date] = new Object();
result[i.date].servicos = i.servicos;
result[i.date].remessa = i.remessa;
result[i.date].materiais = i.materiais;
result[i.date].retorno = i.retorno;
result[i.date].entrada = i.entrada;
}
});
This will return you a Object
whose key is the date. For each date it saves the data of each entry of the object.
If you really need to use a vector, you can do the following:
var arr = [{ servicos: 0, remessa: 503, materiais: 0 , retorno: 598, entrada: 0, date: new Date("2011/12/20") },
{ servicos: 302, remessa: 0, materiais: 412 , retorno: 234, entrada: 864, date: new Date("2011/12/20") },
{ servicos: 276, remessa: 211, materiais: 0, retorno: 598, entrada: 864, date: new Date("2011/13/20") },
{ servicos: 543, remessa: 5033, materiais: 412 , retorno: 0, entrada: 864, date: new Date("2011/13/20") },
{ servicos: 876, remessa: 503, materiais: 412 , retorno: 0, entrada: 0, date: new Date("2011/13/20") }];
var result = [];
arr.filter(function (i){
var hasElement = false;
var j;
for(j = 0; j < result.length; j++){
if(result[j].date.getTime() === i.date.getTime()){
hasElement = true;
break;
}
}
if(hasElement){
result[j].servicos += i.servicos;
result[j].remessa += i.remessa;
result[j].materiais += i.materiais;
result[j].retorno += i.retorno;
result[j].entrada += i.entrada;
}else{
result.push(i);
}
});
With this entry, this filter
will return a Array
with two elements in the result
variable.