Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to display date in javascript 
Javascript :: javascript float precision 2 
Javascript :: js object getter 
Javascript :: mangoosejs 
Javascript :: search box in material angular 
Javascript :: sort array without changing the original js 
Javascript :: history javascript 
Javascript :: Vuejs + Laravel router redirection issue 
Javascript :: distinguishing positive numbers in javascript 
Javascript :: Prevent Double tap in React native 
Javascript :: react chart.js 
Javascript :: dom event 
Javascript :: use react awesome slider in react js 
Javascript :: react cors error 
Javascript :: angular input 
Javascript :: The slice JavaScript string method 
Javascript :: checkbox react 
Javascript :: multipart/form-data ajax jquery 
Javascript :: complete ajax request jquery php call | ajax request 
Javascript :: set embed color discord.js 
Javascript :: remove a value to an array of javascript 
Javascript :: adding element to array javascript 
Javascript :: javascript prototype inheritance example 
Javascript :: add class to element vue 
Javascript :: console.log() Print Values Stored in Variables 
Javascript :: how to set selected value of dropdown in javascript 
Javascript :: angular infinite scroll 
Javascript :: import npm dotenv package 
Javascript :: array with object same keys 
Javascript :: Initialize Axios React Redux CRUD API calls 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =