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

Posted Sunshine

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于javascript——数组去重 ,要求在原型链上编程的主要内容,如果未能解决你的问题,请参考以下文章