var arr = [1, 2, 1, 2, 4, 5];
var newArr = [];
var k = 0; // 作为newArr数组的索引
for(let i = 0;i <arr.length;i++){ //外循环:遍历arr数组
let flag = true;
for (let j = 0; j < newArr.length; j++) { //内循环:遍历newArr数组
if (arr[i] ===newArr[j]) {
flag = false;
break;
}
}
if (flag) {
newArr[k] = arr[i];
k++;
}
}
console.log(newArr);