<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
arr = [1, 2, 3, 2, 2, 4, 5, 6, 7, 8, 2, 9];
// for (let i = 0; i < arr.length; i++) {
// for (let j = i + 1; j < arr.length; j++) {
// if (arr[i] === arr[j]) {
// arr.splice(j, 1);
// j--
// }
// }
// }
// console.log(arr);
// for (let i = 0; i < arr.length; i++) {
// const index = arr.indexOf(arr[i], i + 1);
// if (index !== -1) {
// arr.splice(index, 1);
// i--;
// }
// }
// console.log(arr);
const newArr = [];
for (let ele of arr) {
if (newArr.indexOf(ele) === -1) {
newArr.push(ele)
}
}
console.log(newArr);
</script>
</head>
<body>
</body>
</html>
数组去重三种方法
最新推荐文章于 2024-05-20 15:17:08 发布