let arr = [22, 45, 72, 23, 09, 23, 18, 9, 1, 22, 72, 5, 3, 9, 9]
let arr1 = [22, 45, 72, 23, 09, 23, 18, 9, 1, 22, 72, 5, 3, 9, 9]
let arr2 =[1,2,4,6,8,3,2,5,6]
function remove(arr = []) {
if (arr.length === 0) {
alert('请传入数组')
return
}
for (let i = 0; i < arr.length; i++) {
// console.log(arr[i]);
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] == arr[j]) {
arr.splice(j, 1)
j--;
}
}
}
return arr
}
console.log(remove(arr));
JS基础 函数去重
最新推荐文章于 2024-05-14 02:29:29 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)