📮 联系我

邮箱: 1373879565@qq.com

js 遍历数组对象求和

这个通常是求多个商品的总价遇到的情形:

[
    0: {id: 1, name: "服务费", price: "1.00"}
    1: {id: 2, name: "邮寄费", price: "1.00"}
]

求和总价:

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

 

推荐一个 ai 导航网站:https://ainav-wiki.org

posted @ 2019-10-10 14:21  打静爵  阅读(18200)  评论(1)    收藏  举报