数组去重

 1   var a='1324564789798496465498'.split('');
 2         //方法1
 3         var b=new Set(a);
 4         console.log(Array.from(b))
 5         //方法2
 6         var c=a.reduce(function(total, num){
 7             //如果不存在 就push进去total
 8             !total.includes(num)&&total.push(num);
 9             return total;
10         },[]);
11         console.log(c)
12         //方法3
13         var d={};
14         a.map(res=>{d[res]=res});
15         console.log(Object.keys(d))

 

posted @ 2018-08-28 13:46  V黑匣子  阅读(188)  评论(0编辑  收藏  举报