//数组去重
方法1:
let arr = [10,22,30,22,10,6,7,6]
arr = arr.sort()
let result = [arr[0]]
for (let i=1, len=arr.length; i<len; i++) {
arr[i] !== arr[i-1] && result.push(arr[i])
}
console.log(result);
方法2:
for(let i=0;i<arr.length;i++){
for(let j=i+1;j<arr.length;j++){
if(arr[i] === arr[j]) {
arr.splice(j,1);
}
}
}
console.log("arr:",arr);
方法3:
let arr2 = [10,22,30,22,10,6,7,6]
console.log(Array.from(new Set(arr2)))
方法4:
let result2 = [];
for(let i=0;i<arr2.length;i++){
if(result2.indexOf(arr2[i])<0){
result2.push(arr2[i]);
}
}