Reputation: 65
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
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