【发布时间】:2016-08-19 05:49:51
【问题描述】:
我有一个对象:
var stuffData = {
'Fruit': [{
'Name': 'Apple',
'Price': '2'
}, {
'Name': 'Kiwi',
'Price': '4'
}],
'Sport': [{
'Name': 'Ball',
'Price': '10'
}, {
'Name': 'Bike',
'Price': '120'
}],
'Kitchen': [{
'Name': 'Knife',
'Price': '8'
}, {
'Name': 'Fork',
'Price': '7'
}]
}
现在我想从价格列获取总和。
我想过这个
for (var key in stuffData)
{
// and for each key i have to add new array with sum of price or what?
// But how will I display this sum then?
// I haven't any idea how can I deal with this
}
【问题讨论】:
-
您想要所有
Price值的总和,无论类别如何? -
每个类别都有自己的总和
-
也许你应该发布你想要的结果,向我们展示格式等。
标签: javascript arrays node.js object