How to sum values from an array (array)

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 ?

Store the sum in an object property of the controller, and then it can be referenced from the template:

this.totalPrice = 0;
this.venda.produtos.forEach(prod => this.totalPrice += prod.preco);

Incidentally, get in the habit of preferring let over var. It behaves much more logically. JavaScript’s var has totally irrational semantics.

Thanks for the answer, I will adopt yes. After you run your code snippet, it stores prices at a single variable. But now how do I make the sum of them? For example, I need to add the value of 10.00 + 20.00 which will be equal to 30.00 which is what I will display on the screen for the user.

So you added it to your app already? What result did you get?

My console, after the code snippet that passed me:

venda-pdv.ts:130 Os produtos são Calça Feminina
venda-pdv.ts:130 Os produtos são Calça Masculina
venda-pdv.ts:144 010,0020,00 // here is the result, however I expect to get the result of 30.00 which would be the sum of 10.00 + 20.00 = 30.00//

My code does not print anything to console, so I have no idea what you’re talking about.