我有以下樣本陣列(原始陣列具有多於200種元素)如何比較數組的元素並根據條件進行合併?
var array = [
{
"clientid": "ID000002",
"accesstoken": "pllALEl3TlwLL9hHP938H",
"groupname": "ABC",
"ancestorid": "8982857550",
"stroyid": [
"IGN-EXM-001-PDF",
"IGN-EXM-002-PDF"
]
}, {
"clientid": "ID000002",
"accesstoken": "pllALEl3TlwpHOD4aTP38H",
"groupname": "EFG",
"ancestorid": "4705872914",
"stroyid": [
"APP-ENE-FIE-CON",
"APP-ENE-ASS-INS",
"APP-ENE-ASS-CAR",
"APP-ENE-MAT-REA"
]
}, {
"clientid": "ID000002",
"accesstoken": "pllALEl3TlwLL9hHP938H",
"groupname": "ABC",
"ancestorid": "8982857550",
"stroyid": [
"IGN-EXM-001-ZIP",
"IGN-EXM-002-ZIP"
]
}
]
條件=如果(客戶端ID & &祖先ID相同,則合併storyid),因此,輸出應爲這樣的:
[{
"clientid": "ID000002",
"accesstoken": "pllALEl3TlwLL9hHP938H",
"groupname": "ABC",
"ancestorid": "8982857550",
"stroyid": [
"IGN-EXM-001-PDF",
"IGN-EXM-002-PDF",
"IGN-EXM-001-ZIP",
"IGN-EXM-002-ZIP"
]
}, {
"clientid": "ID000002",
"accesstoken": "pllALEl3TlwpHOD4aTP38H",
"groupname": "EFG",
"ancestorid": "4705872914",
"stroyid": [
"APP-ENE-FIE-CON",
"APP-ENE-ASS-INS",
"APP-ENE-ASS-CAR",
"APP-ENE-MAT-REA"
]
}]
請幫我用JavaScript代碼來實現這一點。
你的榜樣合併兩個條目具有不同的ID。 – epiqueras
@ user3742114謝謝 – user3742114
在分組結果中,不同'accesstoken'會發生什麼? –