How to group elements by months in vue

0

I have a set of data similar to this:

[{fecha: '01/06/2018', pago: '30', id: '-LDviH9T9XripkL64-8y'}, {fecha: '02/06/2018', pago: '20', id: '-LDviH9T93spkL64-8y'}]. 

How could I group the elements by months and add the totals? For example:

[50,20,40,50,20,40,40,20,12,21]

Let each element be the total of the month. This is my code:

totalEgreso2() {
            return this.$store.getters.getCargarCheckIn.reduce(function (total, item, index, array){

             return total + item.pago

            },{})
    
asked by Jorge Arturo Huima Ruiz 06.06.2018 в 00:07
source

1 answer

0

In a very simple way it could serve:

let data = [
  {fecha: '01/06/2018', pago: '30', id: '-LDviH9T9XripkL64-8y'},
  {fecha: '02/06/2018', pago: '20', id: '-LDviH9T93spkL64-8y'}
];

function totalEgreso2() {
  let sum = 0;
  data.forEach(item => {
    sum += Number(item.pago);
  });
  return sum;

}

totalEgreso2();
    
answered by 12.06.2018 / 22:00
source