Why can not I sum prices in foreach loop that I wrote for web api service? It takes only last price for last index bills.bills[6].price
export class BillManager {
async updateBill(className) {
const billService = new BillService();
const bills = await billService.get();
bills.bills.forEach((parameter, index) => {
var total=0;
total += bills.bills[index].price;
price.innerHTML = "<b>" + "Total: " + total + "EUR" + "</b>";
});
This gives 5EUR output. It is the last index's price.
Aucun commentaire:
Enregistrer un commentaire