js数组去重

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr=[1,1,1,22,22,222,1312,546];
        var newArr=[]
        for(var i=0;i<arr.length;i++){
            console.log(arr[i]);
            if(newArr.indexOf(arr[i])===-1){
                newArr.push(arr[i])
            }
        }
        console.log(newArr);
    </script>
</body>
</html>
posted @ 2020-11-10 13:01  无敌臭弟弟  阅读(64)  评论(0编辑  收藏  举报