js数组去重几种方法

//数组去重
Array.prototype.unique1 = function(){
var n = [];
for(var i=0;i<this.length;i++){
if(n.indexof(this[i])==-1){
n.push(this[i]);
}
}
return n;
}
//利用对象
Array.prototype.unique2 = function(){
var n = [];
var obj = {};
for(var i=0;i<this.length;i++){
if(!obj[this[i]]){
n.push(this[i]);
}
}
return n;
}
//indexof
Array.prototype.unique3 = function(){
var n =[];
n.push(this[0]);
for (var i = 1; i < this.length; i++) {
if(this.indexof(this[i])==i){
n.push(this[i]);
}
}
return n;
}

原文地址:https://www.cnblogs.com/muningxuemelody/p/5978959.html