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

【javascript】——数组去重 ,要求在原型链上编程

时间:2020-01-05 09:42:45      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:uniq   编程   prot   abc   type   去重   function   rip   cti   

Array.prototype.unique = function() {
  var temp = {},
    result = [],
    len = this.length;
  for (var i = 0; i < this.length; i++) {
    if(!temp[this[i]]) {
      temp[this[i]] = ‘abc‘;
      result.push(this[i]);
    }
  }
  return result;
}

【javascript】——数组去重 ,要求在原型链上编程

标签:uniq   编程   prot   abc   type   去重   function   rip   cti   

原文地址:https://www.cnblogs.com/hjysunshine/p/12151459.html

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