js array object traversing sum

This is usually the case seeking more than the total price of goods encountered:

[
     0: {ID:. 1, name: "fee",. Price: "1.00" }
     . 1: {ID: 2, name: "postage",. Price: "1.00" } 
]

Sum total:

let totalPrice = 0
data.reduce((totalPrice, item) => totalPrice + item.price, 0)

 

Guess you like

Origin www.cnblogs.com/pjl43/p/11647695.html