我試圖重新集合一個複雜的對象數組。使用多個複合對象對數組項目進行組合
這裏是我的數組:
[
{ scenario: "Treasury", diagnostic: "good results", action: "Manage Financial Recovery"},
{ scenario: "Treasury", diagnostic: "good results", action: "Analyze the impact of your investments"},
{ scenario: "Treasury", diagnostic: "Significant decline", action: "Ensure an adequate"},
{ scenario: "Treasury", diagnostic: "Significant decline", action: "Pilot your cash"},
{ scenario: "Turnover", diagnostic: "Improve trade efficiency of your business", action: "Valorize your labels"},
{ scenario: "Turnover", diagnostic: "Improve trade efficiency of your business", action: "Analyze the opportunity"}
{ scenario: "Turnover", diagnostic: "Improve trade efficiency of your firm", action: "Contacter un prestataire"}
];
我想統一上面這一個數組:
[
{
scenario: "Treasury",
diagnostics: [
{
diagnostic : "good results",
actions: [
"Manage Financial Recovery",
"Analyze the impact of your investments"
]
}
{
diagnostic : "Significant decline",
actions: [
"Ensure an adequate",
"Pilot your cash"
]
}
]
},
{
scenario: "Turnover",
diagnostics: [
{
diagnostic : "Improve trade efficiency of your business",
actions: [
"Valorize your labels",
"Analyze the opportunity"
]
}
{
diagnostic : "Improve trade efficiency of your firm",
actions: [
"Contacter un prestataire"
]
}
]
}
];
所以我試圖用JSBin統一我的數組,但我並沒有得到預期的結果,那麼獲得一個沒有重複項的數組的最有效方法是什麼?
的[什麼是最有效的方法來GROUPBY對象的一個JavaScript陣列上?](HTTP可能重複:// stackoverflow.com/questions/14446511/what-is-the-most-efficient-method-to-groupby-on-a-javascript-array-of-objects) –
可能,但我的數組和我的預期結果是更復雜的和回答並沒有幫助我解決用戶想要統一的其他問題中的問題Ÿ兩個鍵在我的陣列中我有很多重複的鍵要統一 –
請嘗試http://stackoverflow.com/q/36196298/215552。這個問題和問題已經在SO上反覆提出。 –