1.indexOf去重
var a = [1,5,8,7,9,4,5,2,1,3],
b = [];
for(var i = 0;i<a.length;i++){
if(b.indexOf(a[i]) === -1){
b.push(a[i])
}
}
conssole.log(b)
2.includes去重
var a = [1,5,8,7,9,4,5,2,1,3],
b = [];
for(var i = 0;i<a.length; i++){
if(!b.includes(a[i])){
b.push(a[i])
}
}
conssole.log(b)
3.es6中filter去重
var a = [1,5,8,7,9,4,5,2,1,3],
b = [];
a.filter((item)=>{
return b.includes(item)?'':b.push(item)
})
console.log(b)