数组去重的方法
一、数组遍历法
var arr=[10,2,2,3,4,5,3]
var newArr=[];
for(var i=0;i<arr.length;i++){
if(newarr.indexof(arr[i]===-1){
newArr[i].push(arr[i])
}
}
二、数组下标判断法
var arr = [2, 8, 5, 0, 5, 2, 6, 7, 2]
var newArr = []
for (var i = 0; i < arr.length; i++)
{ if (arr.indexOf(arr[i]) === i) {
newArr.push(arr[i])
}
}
三、排序后相邻去除法
var arr = [2, 8, 5, 0, 5, 2, 6, 7, 2]
arr.sort()
var newArr = [arr[0]]
for (var i = 1; i < arr.length; i++) {
if (arr[i] !== newArr[newArr.length - 1]) {
newArr.push(arr[i])
}
}
console.log(newArr)