【JS】数组去重方法

Array.prototype.unique = function(){
 var res = [];
 var json = {};
 for(var i = 0; i < this.length; i++){
  if(!json[this[i]]){
   res.push(this[i]);
   json[this[i]] = 1;
  }
 }
 return res;
}

 

posted @ 2017-08-23 09:37  丰study  阅读(109)  评论(0)    收藏  举报