<script> let arr = [2, 3, 4, 4, 6, 66, 4, 743, 243, 22, 2, 4]; //

for (let i = 0; i < arr.length; i++) { if (array.indexOf(arr[i]) == -1) {
array.push(arr[i]) } } return array; } // 排序后相邻去除，排序后对原数组进行遍历，如果与新数组的length -
1的值不同，就添加到新数组中最后输出新数组 function sortNum(a, b) { return a - b; } function
second(arr) { arr.sort(sortNum) let array = [arr[0]] for (let i = 0; i <
arr.length; i++) { if (arr[i] != array[array.length - 1]) { array.push(arr[i])
} } return array; } // 优化遍历数组法（推荐） function third(arr) { let array = []; for
(let i = 0; i < arr.length; i++) { for (let j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) { ++i } } array.push(arr[i]); } return array; } // ES6
set，set方法由ES6提供，里面的值都是唯一的 function setArr(arr) { let es6Set = new Set(arr)
return [...es6Set]; } console.log('遍历数组法') console.log(first(arr))
console.log('排序后相邻去除法') console.log(second(arr)) console.log('ES6 set')
console.log(setArr(arr)) console.log('优化遍历数组法') console.log(third(arr))
</script>

let arr1 = [1, 25, 2, 26, 1234, 6, 213]; let arr2 = [2, 6, 2134, 6, 31, 623];
let c = [...new Set([...arr1, ...arr2])].sort((a, b) => { return a - b; });
//(10) [1, 2, 6, 25, 26, 31, 213, 623, 1234, 2134]