[removed] How group and sum values from multidimensional array

前端 未结 5 628
广开言路
广开言路 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:30

    Using lodash:

    var data; // the data represented by your screenshot
    
    var counts = _.chain(data)
        .groupBy('AGENDADOR')
        .map(_.size)
        .value();
    

    counts will now be an object like this:

    {
        "AGE270": 9,
        "AGE203": 5,
        // etc
    }
    

提交回复
热议问题