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

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;
}

猜你喜欢

转载自www.cnblogs.com/hjysunshine/p/12151459.html