hello, i would like to know how to create a subtotal price of an array + a delivery fee which is not inside the array
i tried this but the delivery fee is rejected, how to include this delivery fee into the subtotal?
at the TS
deliveryfee=// this comes from another function which has no issue at show the fee at ngoninit and ionviewdidenter
subtotaltest(arr) {
let total = 0;
arr.forEach(element => {
total += parseFloat[(element.price) * element.quantity] + this.deliveryfee;
});
return total
}
at HTML
Sub Total: {{ subtotaltest(product) | currency : ‘USD’}}
subtotaltest(arr) {
let total = 0;
arr.forEach(element => {
total += parseFloat(element.price * element.quantity) + this.deliveryfee;
});
return total
}
the reduce method works, but when i try to push subtotal into array, it went crazy, i push 1 it becomes 2, i push 2 it becomes 3, so the correct figure i cannot get it.
Sorry, yeah I think what I was thinking requires you to use array.map() to get subtotals first.
//create a new array of items of the totals for each item
//reduce the new array to the sum of the values,
//with a starting value of you delivery fee
let total = cartArray
.map((element) => element.price * element.quantity)
.reduce((acc, curr) => { return acc + curr}, deliveryFee);