1 回答

TA貢獻1818條經(jīng)驗 獲得超3個贊
function handle(arr) {
var res = [],
obj = {},
index = 0;
arr.forEach(val => {
if (obj.hasOwnProperty(val.UID)) {
res[obj[val.UID]].value = res[obj[val.UID]].value + ',' + val.value;
} else {
obj[val.UID] = index++;
res.push({
UID: val.UID,
value: val.value
});
}
});
return res;
}
var arr = [{
UID: "222",
value: "111"
}, {
UID: "222",
value: "103"
}, {
UID: "123",
value: "302"
}, {
UID: "123",
value: "031"
}]
console.log(handle(arr))
添加回答
舉報