方法一:for循环
for(var i=0;i<arr.length;i++){
for(var j=i+1;j<arr.length;j++){
if(arr[i] == arr[j]){
arr.splice(j,1);
i--;
}
}
}
方法二:indexOf
var temp = [];
for(var i=0;i<arr.length;i++){
if(temp.indexOf(arr[i]) < 0){
temp.push(arr[i]);
}
console.log(temp);
}
方法三:es6.set
var set = [...new Set(arr)];
方法四:对象
var obj = {};
var oop = [];
for(var i = 0 ;i< arr.length;i++){
if( !obj[arr[i]] ){
obj[arr[i]] = 1;
oop.push(arr[i]);
}
}
console.log(oop);
方法五:filter
var arr2 = arr.filter(function(element,index,self){
return self.indexOf(element) === index;
});
console.log(arr2);