Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

reduce累加能加判断吗?应该怎么加?

$
0
0

像下面这样,有一个mainDataList对象数组,我想求数组里对象状态不为0 的transactionAmount的和,是加一个if判断吗?怎么加?加在哪里? totalBalance() { if (!this.mainDataList) { return 0 } return this.mainDataList.reduce((prev, cur) => { // if (prev.state !== 0) //不知道怎么加进去 return (parseFloat(cur.transactionAmount) + parseFloat(prev)).toFixed( 2 ) }, 0) } 请各位大神帮忙看看,谢谢


Viewing all articles
Browse latest Browse all 14821

Latest Images

Trending Articles