每天一篇js ——在内置类的原型上扩展方法

212 阅读1分钟
Array.prototype.distinct = function Distinct(){
    var obj = [];
    for(var i = 0;i< this.length;i++){
        var item = this[i];
        if(obj[item] != undefined){
            this[i] = this[this.length - 1];
            this -- ;
            i--;
            continue;
        }
        obj[item] = item;
    }
    obj = null;
    return this;
}