//1、使用new Set
//2、indexOf
//3、先排序,后比较
//1、使用new Set
var a = [1, 2, 1, 3, 2, 1]
var arr=new Set(...[a]);
console.log(Array.from(arr));
//2、indexOf
var a = [1, 2, 1, 3, 2, 1]
var arr = [];
for (var i = 0; i < a.length; i++) {
if (arr.indexOf(a[i]) == -1) {
arr.push(a[i])
}
}
console.log(arr)
//3、先排序,后比较
var a = [1, 2, 1, 3, 2, 1];
a.sort();
var arr = [];
for (var i = 0; i < a.length; i++) {
if (a[i] !== a[i + 1]) {
arr.push(a[i])
}
}
console.log(arr)