JS数组去重

 给Array本地对象添加一个原型方法,用于删除数组中的重复的条目(可能有有多个),返回值是一个包含被删除的重复条目的数组:

Array.prototype.Distinct = function(){
    var res = [];
    for(var i=0;i<this.length;i++){
        for(var j=i+1;j<this.length;){
            if(this[i]===this[j]){
                res.push(this.splice(j,1));
            }else{
                j++;
            }
        }
    }
    return res;
}

alert(['a','b','c','d','b','a','c'].Distinct());
原文地址:https://www.cnblogs.com/skylar/p/3608618.html