SOURCE

/**
 * 需要去重数组每项中具有重复属性的项
 * 
 * 例如:
 * list:[{name,12,age:11},{name:23,age:45},{name,12,age:11}]
 * 得到结果
 * list:[{name,12,age:11},{name:23,age:45}]
 * 
 * arr表示传递的数据  keys表示需要过滤的重复项
 */
function newArrFn(arr, keys) {
    // 创建一个新的空数组
    let newArr = []
    for (let i = 0; i < arr.length; i++) {
        // 设置一个开关,如果是true,就存进去,不是就不存
        let flag = true
        for (let j = 0; j < newArr.length; j++) {
            // 原数组和新数组作比较,如果一致,开关变为 false
            // arr[i].fanwei === newArr[j].fanwei && arr[i].leixing === newArr[j].leixing  ? flag = false : flag
            let flag2 = true
            if (flag2) {
                for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
                    if (arr[i][keys[keyIndex]] === newArr[j][keys[keyIndex]]) {
                        flag2 = false
                        flag = false
                    }
                }
            }
        };
        flag ? newArr.push(arr[i]) : newArr
    };
    return newArr
}

let list = []
for (var i = 0; i < 10; i++) {
    if (i % 3 == 0) {
        list.push({
            name: `nameqw`,
            age: `age90`
        })
    }
    else if (i % 2 == 0) {
        list.push({
            name: `name${i * 2.5}`,
            age: `age${i * 2.5}`,
            grens: `grens-${i}-wqqo`
        })
    } else {
        list.push({
            name: `name${i}`,
            age: `age${i}`,
            obj: `fidi${i * 3.6}`
        })

    }
}
// console.log("list", list)

const arr = newArrFn(list, ['name', 'age'])
console.log(arr)
console 命令行工具 X clear

                    
>
console