-3
我有對象的數組是這樣的:如何總結對象陣列相同的密鑰值
var original_db = [
{date_diff:"2016/10/31", date_number:1,hangup_cause:"NORMAL_CLEARING"},
{date_diff:"2016/10/31", date_number:1,hangup_cause:"NORMAL_CLEARING"},
{date_diff:"2016/10/31", date_number:1,hangup_cause:"NO_ANSWER"},
{date_diff:"2016/10/31", date_number:1,hangup_cause:"ORIGINATOR-CANCEL"},
{date_diff:"2016/10/30", date_number:2,hangup_cause:"NORMAL_CLEARING"},
{date_diff:"2016/10/30", date_number:2,hangup_cause:"NO_ANSWER"},
{date_diff:"2016/10/30", date_number:2,hangup_cause:"NO_ANSWER"},
{date_diff:"2016/10/30", date_number:2,hangup_cause:"NO_ANSWER"},
{date_diff:"2016/10/29", date_number:3,hangup_cause:"NORMAL_CLEARING"},
{date_diff:"2016/10/29", date_number:3,hangup_cause:"ORIGINATOR-CANCEL"},
{date_diff:"2016/10/29", date_number:3,hangup_cause:"ORIGINATOR-CANCEL"},
];
這裏是我期望的結果:
result :
[
{date_diff : "2016/10/31", NORMAL_CLEARING : 2, NO_ANSWER : 1, ORIGINATOR-CANCEL : 1},
{date_diff : "2016/10/30", NORMAL_CLEARING : 1, NO_ANSWER : 3},
{date_diff : "2016/10/29", NORMAL_CLEARING : 1, ORIGINATOR-CANCEL : 2}
]
是否有一個簡單的方法來做到這一點?
是。你試過什麼了? – GAntoine
我試試這段代碼..... var dict = {}; for(i = 0; i
user7238915
請回顧[問],並更新您的問題,以包括你嘗試***的[mcve],否則這個問題是[off-topic(#1)](/ help/on-topic )。 – zzzzBov