JavaScript---数组去重

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/JamieCheung/article/details/82694321
// 数组去重
Array.prototype.distinct = function(){
  var arr = this,
      result = [],
      i,
      j,
      len = arr.length;
  for(i = 0; i < len; i++){
    for(j = i + 1; j < len; j++){
      if(arr[i] === arr[j]){
        j = ++i;
      }
    }
    result.push(arr[i]);
  }
  return result;
}



var ss = searchArr.distinct();
localStorage.setItem('search', ss);

猜你喜欢

转载自blog.csdn.net/JamieCheung/article/details/82694321