当前位置:网站首页>Native JS array some method de duplication

Native JS array some method de duplication

2022-06-25 19:16:00 Good first

<!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>
</head>

<body>
    <script>
       
        //some()  As long as there is one satisfaction, return true;
        var arr = [1, 1, 2, 2, 3, 3, 2, 4, 1];
        var newArr = [];
        for (let i = 0; i < arr.length; i++) {
    
           
            if (newArr.some(item => item == arr[i])) {
    
                continue; //  Continue to cycle 
            }
            newArr.push(arr[i]);
        }
        console.log(newArr);

    </script>
</body>

</html>
原网站

版权声明
本文为[Good first]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190519033865.html