reduce遍历

63 阅读1分钟

image.png image.png

const arr=[
        {id:1,naem:"西瓜",satae:true,price:20,count:1},
        {id:1,naem:"葡萄",satae:true,price:30,count:2},
        {id:1,naem:"草莓",satae:true,price:50,count:3}
    ]
    const result=arr.filter(item=>item.satae).reduce((amt,item)=>amt+=item.price*item.count,0)
       console.log(result);