js去重

1、indexOf

let a = [1,2,3,3, 4,1, NaN, 0, undefined, NaN ]
let arr = [];
for(let i = 0; i < a.length; i++) {
    if( arr.indexOf(a[i]) == -1) {
        arr.push(a[i])
    }
}
console.log(arr)

2、es6 new map写法

let a = [1,2,3,3, 4,1, NaN, 0, undefined, NaN ]
let map = new Map();
let arr = [];
a.forEach((item) => {
    if(!map.has(item)) {
        map.set(item)
        arr.push(item)
    }
})
console.log(arr)