js 删除 数组重复

js删除数组重复

Array.prototype.unique = function() {
    var a = {};
    for (var i = 0; i < this.length; i++) {
        if (typeof a[this[i]] == "undefined")
            a[this[i]] = 1;
    }
    this.length = 0;
    for (var i in a)
        this[this.length] = i;
    return this;
}



posted @ 2012-02-13 14:20  wangkangluo1  阅读(592)  评论(0编辑  收藏  举报