js去除数组里重复数据

最近工作中使用到js数组去重复,做个笔记

    //去除数组里的重复
    Array.prototype.distinct = function() {
        var a = {}, c = [], l = this.length;
        for (var i = 0; i < l; i++) {
            var b = this[i];
            var d = (typeof b) + b;
            if (a[d] === undefined) {
            c.push(b);
            a[d] = 1;
            }
        }
    return c;
    }

 var ColorArr = ["X", "X", "M"];
 var ItemColor = ColorArr.distinct();
console.log(ItemColor);

 

 

posted @ 2013-09-04 09:18  WEB小蜗牛  阅读(351)  评论(0编辑  收藏  举报