📜  js减少后数组中的两个值 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:04.382000             🧑  作者: Mango

代码示例1
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);