Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js two value from array after reduce

cartTotal(): void {

    const {total, quantity} = this.carrello.plu.reduce((acc, item) => { 
      acc.quantity += item.qta;
      acc.total = acc.total + (item.prezzo * item.qta);
      return acc;
    }, {total:0, quantity:0});

	this.cartCount.next(acc.quantity);  // emit whatever you want to emit.  
}

console.log('Total Price', total, 'Total Quantity', quantity);
 
PREVIOUS NEXT
Tagged: #js #array #reduce
ADD COMMENT
Topic
Name
1+5 =