SOURCE

let obj = [
    {
        id: '1001',
        name:'张三',
        project: 'S000B20211021001',
        type:'直接分配',
        num: 1,
        total: 2,
        idNum: 3,
    },
    {
        id: '1002',
        name:'李四',
        project: 'S000B20211021001',
        type:'配额分配',
        num: 4,
        total: 5,
        idNum: 8,
    },
    {
        id: '1003',
        name:'王五',
        project: 'S000B20211021001',
        type:'直接分配',
        num: 004,
        total: 005,
        idNum: 888,
    },{
        id: '1001',
        name:'张三',
        project: 'S000B20211021002',
        type:'直接分配',
        num: 001,
        total: 002,
        idNum: 003,
    },
    {
        id: '1002',
        name:'李四',
        project: 'S000B20211021002',
        type:'配额分配',
        num: 004,
        total: 005,
        idNum: 99
    },
    {
        id: '1003',
        name:'王五',
        project: 'S000B20211021002',
        type:'直接分配',
        num: 022,
        total: 44,
        idNum: 999,
    },{
        id: '1001',
        name:'张三',
        project: 'S000B20211021003',
        type:'直接分配',
        num: 2222,
        total: 8888,
        idNum: 9333,
    },
    {
        id: '1002',
        name:'李四',
        project: 'S000B20211021003',
        type:'配额分配',
        num: 44444,
        total: 2222,
        idNum: 4444
    },
    {
        id: '1003',
        name:'王五',
        project: 'S000B20211021003',
        type:'直接分配',
        num: 666,
        total: 7777,
        idNum: 9999,
    },
]


function tableArr(arr) {
    let testArr = [];
    let resultArr = [];
    for (let i = 0; i < arr.length; i++) {
        if (testArr.indexOf(arr[i].id) === -1) {
            resultArr.push({
            id: arr[i].id,
            name: arr[i].name,
            item: [arr[i]]
            });
            testArr.push(arr[i].id);
        } else {
            for (let j = 0; j < resultArr.length; j++) {
            if (resultArr[j].id == arr[i].id) {
                resultArr[j].item.push(arr[i]);
                break;
            }
            }
        }
    }
    return resultArr
}

let nowArr = new tableArr(obj)

console.log(nowArr)
console 命令行工具 X clear

                    
>
console