1.indexof()
arr = ['1','2','2','3','6','5','5','5','4','4','4','8'];
function unique (arr){
var newArr = [];
for (var i = 0;i< arr.length;i++){
if(newArr.indexOf(arr[i]) === -1){
newArr.push(arr[i]);
}
}
return newArr;
}
console.log(unique(arr));
2.Set方法
arr = ['1','2','2','3','6','5','5','5','4','4','4','8'];
function unique (arr){
return Array.from(new Set(arr));
}
console.log(unique(arr));