码迷,mamicode.com
首页 > 编程语言 > 详细

数组去重方法(ES6)

时间:2017-10-17 16:34:26      阅读:408      评论:0      收藏:0      [点我收藏+]

标签:es6   ref   new   blog   cti   返回   ret   before   from   

 

 1 let arrayBefore = [1,3,3,2,1,5,2,1];  //去重之前的数组
 2 
 3 Array.prototype.dedupe = function (){  //去重函数 返回去重后的数组
 4     let temp = new Set(this);
 5     temp = Array.from(temp);          //转为 Array类
 6     return temp;
 7 
 8 };
 9 
10 arrayBefore.dedupe();    // [ 1, 3, 2, 5 ]

 

参考文献: 阮一峰ECMASript6入门. 电子工业出版社

技术分享

 

数组去重方法(ES6)

标签:es6   ref   new   blog   cti   返回   ret   before   from   

原文地址:http://www.cnblogs.com/tainlx/p/7682141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!