SOURCE

var obj = [
    { id: 1, name: 'aa' },
    { id: 1, name: 'bb' },
    { id: 2, name: 'cc' },
    { id: 3, name: 'ee' },
    { id: 4, name: 'dd' }
]

var _obj = []

for (let i = 0; i < obj.length; i++) {
    if (!_obj.length) {
        _obj.push(obj[i])
    } else {
        let isHas = false
        for (let j = 0; j < _obj.length; j++) {
            if (_obj[j].id == obj[i].id) {
                _obj[j].name += ',' + obj[i].name
                isHas = true
            }
        }
        if (!isHas) _obj.push(obj[i])
    }
}
console.log(_obj)
console 命令行工具 X clear

                    
>
console