【发布时间】:2021-10-09 05:10:44
【问题描述】:
我有以下 JSON 对象:
const data = [
{
"city name": "Chennai",
"product name": "Apple",
"no of qty": 2,
"indvidual price": 50,
"gst tax": 0.18
},
{
"city name": "Chennai",
"product name": "Samsung",
"no of qty": 1,
"indvidual price": 150,
"gst tax": 0.18
},
{
"city name": "Delhi",
"product name ": "MIUI",
"no of qty": 5,
"indvidual price": 100,
"gst tax": 0.18
},
{
"city name": "Chennai",
"product name": "Redmi",
"indvidual price": 100,
"no of qty": 1,
"gst tax": 0.18
},
{
"city name": "Delhi",
"product name": "Realme",
"indvidual price": 100,
"no of qty": 5,
"gst tax": 0.18
},
];
我正在尝试根据城市和计算总体数量和成本进行分组。基于单个产品的总成本有不同的 GST,我们需要计算并添加到总价值中。
例外的JSON是这样的,
var result = [
{
"city": "chennai",
"totalqty": 4, //Total qty based on the city
"totalPrice": 354 //With the GST, Each product have separate gst(59+177+118)
},
{
"city": "Delhi",
"totalqty": 10, //Total qty based on the city
"totalPrice": 236 //With the GST, Each product have separate gst(118+118)
}
]
【问题讨论】:
标签: javascript node.js arrays json reactjs