Home > database >  how to sum or calculate value in array use vue
how to sum or calculate value in array use vue

Time:10-30

i have data array in this

"item_tabel": [
  {
    "method": {
      "select_method": 6,
      
    },
    "innovation": {
      "select_innovation": 2,
    },
  }
],

how to calculate using sum ?

this my computed

subtotalRow() {
    return this.$store.state.item_tabel.map((item,i) => {
      return Number(item.method.select_method * item.innovation.select_innovation)
      //how to sum (item.method.select_method   item.innovation.select_innovation)
     });
 },

example in my table

No | method | inov | total
1  |    6   |  2   | (6 2 = 8) //calculate
2  |    2   |  2   |  4        //calculate 

if using operator * works and if using doesn't work

thks

CodePudding user response:

If you really want to add the 6 and 2

Surely all you need to do is what you have written in your comment line?
subtotalRow() {
    return this.$store.state.item_tabel.map(
        (item,i) => (item.method.select_method   item.innovation.select_innovation)
    );
 },

CodePudding user response:

This should work for you;

subtotalRow() {
    return this.$store.state.item_tabel.map(
        (item,i) => {item.method.select_method   item.innovation.select_innovation}
    );
 },
  • Related