在 React JS 中获取值的总和

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}
   ]
}

如何在react中获取poDetailsList subTotal的总和赋值给goodReceiveNote中的netTotal

将数组 reduce 与 Object.values

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