慕丝7291255
function parse(data) { const hash = {}; data.slice().forEach(item => { const path = item.path; if (!hash[path]) { hash[path] = item; } else { Object.keys(item).forEach(key => { const hashPath = hash[path]; if (key !== "path") { const val = item[key]; if (!hashPath[key]) { hashPath[key] = val; } else { if (!Array.isArray(hashPath[key])) { hashPath[key] = [hashPath[key]]; } hashPath[key] = hashPath[key].concat(val); } } }) } }); return Object.keys(hash).map(key => hash[key]);}var test = [ { "path": "client_01", "client_list": [ { "client": "test_01", } ], "share_type": 1, }, { "path": "client_01", "group_list": [ { "group": "groupData", } ], "user_list": [ { "user": "userData", } ], "share_type": 2, }, { "path": "client_02", "client_list": [ { "client": "test_02", } ], "share_type": 1, }, { "path": "client_02", "group_list": [ { "group": "groupData_02", } ], "user_list": [ { "user": "userData_02", } ], "share_type": 2, }];console.log(parse(test));