首页 > 其他 > 详细

过滤filter去掉重复的数据

时间:2021-04-15 23:43:05      阅读:28      评论:0      收藏:0      [点我收藏+]
<!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>

过滤filter去掉重复的数据

原文:https://www.cnblogs.com/czb1218/p/14664229.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!