第一种:
var ary=[1,4,2,3,6,4,7,8,4,2];
for(var i=0;i<ary.length;i++){while(ary.indexOf(ary[i])!==ary.lastIndexOf(ary[i])){
ary.splice(i,1);
}
}
console.log(ary);
第二种:
var ary=[1,2,2,4,45,,4252,42];for (var i=0;i<ary.length;i++) {
if(ary.indexOf(ary[i])!==ary.lastIndexOf(ary[i])){
ary.splice(i,1);
}
}
console.log(ary);
第三种:
var ary=[1,4,2,3,6,4,7,8,4,2];var obj={};
for (var i=0;i<ary.length;i++) {
obj[ary[i]]=ary[i];
}
var ary1=[];
for (key in obj) {
ary1.push(obj[key])
}
console.log(ary1)
第四种:
var ary=[1,4,2,3,6,4,7,8,4,2];var ary3=[];
for (var i=0;i<ary.length;i++) {
if(ary3.indexOf(ary[i]==-1)){
ary3.push(ary[i]);
}
}
console.log(ary3);
第五种:
var ary=[1,4,2,3,6,4,7,8,4,2];var ary4=[];
ary.forEach(function(item,index,input){
if(ary4.index(item)==-1){
ary4.push(item);
}
})
console.log(ary4);