JSFiddle - React, Tailwind, and code Playground
by Azuk
JavaScript
var productsInCart = [{"id":1,"price":25,"quantity":5}, {"id":2,"price":5,"quantity":1},{"id":3,"price":8,"quantity":1}];
var totalCost = 0;
for (var product in productsInCart){
totalCost = totalCost+(productsInCart[product].price * productsInCart[product].quantity);
}
alert(totalCost);