I would like to know how I can get the sum of numeric values inside an array. My case is this, I am building a sales screen, currently I have an array with the products that the user selects to sell, I am displaying them on the screen normally. But I need to capture every value (price) of each product, and in the end I need to add all prices to get the full value of the sale, but I’m not sure how.
My current structure is as follows:
//I capture the selected product object, 1 or more products//
if(produto.selecionado == true && produto.selecionado >= 1){
this.produtosMarcados.push(produto);
}
this.venda.produtos = this.produtosMarcados;
console.log(this.venda.produtos);
}
//Capture the item description and values//
//Capture the description of products, works perfectly//
var i: any;
for (i=0; i < this.venda.produtos.length; i++){
console.log("Os produtos são " +this.venda.produtos[i].descricao);
}
//Capture the price of each item, works perfectly//
var v: any;
for (v=0; v < this.venda.produtos.length; v++){
console.log("Os valores são " +this.venda.produtos[v].preco);
}
After capturing the values of the items, as is happening in the second FOR, I need to sum all the values that would be contained within this array, how can I do this? Any idea ?