SOURCE

let arr = [
    {a: 1, b: 2, tag: 9},
    {a: 2, b: 3, tag: 9},
    {a: 1, b: 2, tag: 7},
];
let brr = [
    {a: 2, b: 3, tag: 9},
];


function groupByArr(arr, field, isObj){
    let obj = {};
    arr.forEach(one=>{
        let key = one[field];
        if(!obj.hasOwnProperty(key)){
            obj[key] = [];
            obj[key].push(one);
        }else{
            obj[key].push(one);
        }
    });
    if(isObj) return obj;
    let groupList = [];
    objValues = Object.values(obj);
    objValues.forEach(value=>{
        groupList.push(value);
    });
    return groupList;
}


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

                    
>
console