var arr = [1, 2, 3, 3, 3, 4, 5, 2, 1, 6, 7, 7, 8, 5, 6, 9];
过滤数组
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);
// 回溯
j--;
}
}
}
var newArr = [];
for (var i = 0; i < arr.length; i++) {
if(newArr.indexOf(arr[i]) == -1){
newArr.push(arr[i]);
}
}
console.log(newArr);