高效数组去重

  1. Array.prototype.unique = function()  
  2. {  
  3.     var n = {}, r = [], len = this.length, val, type;  
  4.     for (var i = 0; i < this.length; i++) {  
  5.         val = this[i];  
  6.         type = typeof val;  
  7.         if (!n[val]) {  
  8.             n[val] = [type];  
  9.             r.push(val);  
  10.         } else if (n[val].indexOf(type) < 0) {  
  11.             n[val].push(type);  
  12.             r.push(val);  
  13.         }  
  14.     }  
  15.     return r;  
  16. }  
原文地址:https://www.cnblogs.com/zhangxy1018/p/5920546.html