过滤filter去掉重复的数据

<!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>
        function unique(arr){
            //分别遍历循环数组里面的数值,角标
            return arr.filter(function(item,index,arr){
                //当前元素,在原始数组里面的第一个索引值全等于当前的索引值,否则返回当前元素
                return arr.indexOf(item,0)===index
            })
        }
        const arr =[1,5,6,1,2,5,4,8,6,8]
        console.log(unique(arr))
    </script>
</body>
</html>
posted @ 2021-04-15 20:07  干饭吧  阅读(968)  评论(0编辑  收藏  举报