//数组去重
var arr = [1, 2, 2, 3, 4, 5, 3, 2, 1, 4]
var newArr = []
//1.利用indexof去重
//1遍历原数组
for (var i = 0; i < arr.length; i++) {
if (newArr.indexOf(arr[i]) == -1) {//等于-1说明新数组中没有这个元素
newArr.push(arr[i])
}
}
console.log(newArr);
//2.利用对象属性不可重复去重
var obj = {
}
for (var i = 0; i < arr.length; i++) {
obj[arr[i]] = arr[i]
}
//遍历对象
for (var k in obj) {
newArr.push(k)
}
console.log(newArr);