[removed] How group and sum values from multidimensional array

前端 未结 5 630
广开言路
广开言路 2020-12-21 10:10

I have an array like this:

I would like to group and get the sum of each repetition like this:

  • AGE270: 9
  • AGE203: 5
  • AGE208: 9
5条回答
  •  温柔的废话
    2020-12-21 10:43

    Try this out:

    function( data ){
            var outputObj = {} ;
            for(var i=0;i < data.length; i++){
                     datum = data[i];
                     if(outputObj[datum.AGENDADOR])
                             outputObj[datum.AGENDADOR] += parseInt( datum.TOTAL) ;
                     else
                             outputObj[datum.AGENDADOR] = parseInt( datum.TOTAL);
                    }
    
            return outputObj;
    

    };

提交回复
热议问题