I'm having a little problem here with counting array of object values... The code I have below works just fine but what if I want to target only certain objects within the reduce function?
Basically, something like an SQL WHERE function, so
newcost = Number((cart.map(item => (item.cost * item.amm)).reduce((prev, next) => Number(prev) + Number(next))).toFixed(2));
would be
newcost = Number((cart.map(item => (item.cost * item.amm)).reduce((prev, next) => Number(prev) + Number(next))).toFixed(2)) WHERE item.type === "c";
You know, something similar to this. How can I achieve something like this?
Thank you.
.filterin between:x.map().filter(...).reduce(...)filter