I have online shopping app in react .I have Invoice array called invItems
and products called items
in that array. I want to calculate the price*quantity of all the items in invItems
array.
moreover I want to calculate the total quantity of all object (items) in the invoice.
the code is give as below:
useEffect(()=>{
if(invItems.length>0){
var invtotal=0.0;
var total=invItems.reduce((invTotal,x)=>(invTotal+=x.total));
var sum=0;
sum=invItems.reduce((sum,x)=>(sum+=x.qty));
console.log("result:",total,sum );
}
},[invItems])
console.log("invItems:",invItems);
each Item is object as below:
const newItem={
OId:'',
productId: '',
productName: '',
productCode: '',
qty:1,
price: 0.0,
total:0.0,
}
the result is not correct or in correct form please see the console in screenshots.