使用es6新增Set函数快速数组去重

使用new Set()快速数组去重:

  let arr = [1, 2, 2, 3, 4, 5, 5, 5, 6]
    let set = new Set([...arr])
    console.log([...set]) //[1, 2, 3, 4, 5, 6]


    function SetArr(array) {
        return Array.from(new Set(array));
    }
    console.log(SetArr([1, 1, 2, 2, 3, 4, 4]))  // [1, 2, 3,4]

猜你喜欢

转载自www.cnblogs.com/lwming/p/11123461.html