我有数组:array = [ { "id": 1, "Price": 100, "Item": {"id": 1, Name: "A"}, "Date": {"id": 1, Start: "202001"} }, { "id": 2, "Price": 200, "Item": {"id": 1, Name: "A"}, "Date": {"id": 2, Start: "202002"} }, { "id": 3, "Price": 300, "Item": {"id": 3, Name: "B"}, "Date": {"id": 2, Start: "202002"} } ]我希望能够对给定时间段内的值进行求和,如下表所示:物品202002202003全部的A100200300乙300300全部的100500600有什么建议吗?感谢!
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
看看这个,它会让你走上正确的道路
var aHolder = 0;
for(var i = 0; i<array.length; i++){
if(array[i].Date.Start === '202002') {
aHolder = aHolder + array[i].Price;
}
}
console.log(aHolder);
添加回答
举报
0/150
提交
取消