I'm creating a POS system with ReactJS. Should I use a for loop to calculate the total amount? Is there any other way to do this?
let product = testProducts;
let subtotalEl = document.getElementsByClassName("Subtotal");
let quantity = document.getElementsByClassName("Quantity");
for (var i = 0; i < product.length; i++) {
subtotalEl[i].innerHTML = product[i].UnitPrice * quantity[i].value;
}
map for iterations.For example:
const sum = array_object
.map((item) => item.quantity)
.reduce((prev, curr) => prev + curr, 1);
As you can see, map was used to go through the array, and reduce to add the values.