Js实现数组去重

  /*数组去重*/
    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;
    }
    tagsArr.distinct();
解释: tagsArr是待去重的数组

猜你喜欢

转载自blog.csdn.net/zhang18330699274/article/details/79215450
今日推荐