我有一個json,其數組被稱爲chargeamountunitLevel。我想由chargeAmountUnit.The輸入JSON分組總結行動的chargeAmount:如何使用節點-js使用聚合函數
"chargeamountunitLevel": [
{
"chargeAmount": 4,
"chargeAmountUnit": "per hour",
"currencyCode": "USD"
},
{
"chargeAmount": 50,
"chargeAmountUnit": "per hour",
"currencyCode": "USD"
},
{
"chargeAmount": 25,
"chargeAmountUnit": "per month",
"currencyCode": "USD"
},
{
"chargeAmount": 25,
"chargeAmountUnit": "per month",
"currencyCode": "USD"
}
]
結果可能如下:
"chargeamountunitLevel": [
{
"chargeAmount": 54,
"chargeAmountUnit": "per hour",
"currencyCode": "USD"
},
{
"chargeAmount": 50,
"chargeAmountUnit": "per month",
"currencyCode": "USD"
}
]
有什麼建議?
由你工作的好方法,但不能理解爲什麼我在結果中得到重複值 – Prem
@Prem,你能舉個例子嗎? – plalx
我已解決獲取重複項(我在console.log(結果)重複,但主要的事情,我不能從谷歌得到它是如何修改您的代碼,如果我想通過基於chargeAmountUnit和currencyCode分組。 – Prem