Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70889

Sum of dynamic objects in array

$
0
0

Hi, I have the below array whose object will increase and decrease dynamically. and each time I need to
get the total by doing “price” * “quant”.

[
    {
        "id": "95",
        "price": 100,
        "quant": 1
    },
    {
        "tovar_id": "73",
        "price": 4,
        "quant": 2
    },
    {
        "tovar_id": "75",
        "price": 10,
        "quant": 2
    }
]

I need something like
total = 28

I have tried this way and it reset the total value each time a new object added to it.

total(){

    if (this.sell.length > 0) {

      for(let i = 0; i < this.sell.length; i++){

        this.itemstotal = this.sell[i]['quant']*this.sell[i]['price'];

        break;

      }

      console.log("TOTAL ",this.itemstotal);

    }

  }

Thanks in advance.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 70889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>