SOURCE

// 数组去重
function duplicateRemoval (arr) {
    const set = new Set(arr);
    return Array.from(set);
}

function duplicateRemoval2 (arr) {
    const newArr = []
    arr.forEach(v => {
        if (!newArr.includes(v)) {
            newArr.push(v);
        }
    })
    return newArr;
}

function duplicateRemoval3 (arr) {
    const obj = {};
    const array = []
    arr.forEach(v => {
        let key = JSON.stringify(v);
        if (obj[key] === undefined) {
            array.push(v)
            obj[key] = true
        }
    });
    return array
}

function duplicateRemoval4 (arr) {
    return arr.sort().reduce((acc, v) => {
        if (acc.length === 0 || acc[acc.length -1] !== v) {
            acc.push(v)
        }
        return acc;
    }, []);
}

const a = [1,1,'1','str',null,null,[1,2,3],[1,2,3],123,{},{a: 1},2,3,4,0,0,4,8,7,5,4,6,4]
console.log(duplicateRemoval(a))
console.log(duplicateRemoval2(a))
console.log(duplicateRemoval3(a))
console.log(duplicateRemoval4(a))
console 命令行工具 X clear

                    
>
console