Waqas
Waqas

Reputation: 65

Get the Sum of Values in React JS

data: {
   goodReceiveNote:{ id:1,netTotal: null}
   poDetailsList:[
     0:{id:1,subTotal:300},
     1:{id:1,subTotal:200}
   ]
}

How to get the sum of poDetailsList subTotal and Assign it to the netTotal in goodReceiveNote in react.

Upvotes: 2

Views: 149

Answers (1)

BENARD Patrick
BENARD Patrick

Reputation: 30975

Use the array reduce in combinaison with Object.values

const total = Object.values(data.poDetailsList).reduce((a,b) => a + b.subTotal, 0)

Upvotes: 1

Related Questions