1. 程式人生 > >JS 去除重復元素的方法

JS 去除重復元素的方法

func style col ret proto ray urn spa ons

Array.prototype.del = 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 Ary = ["
生活服務類", "健康保健類", "便民服務", "社區服務", "生活服務類", "健康保健類", "便民服務", "社區服務"] Ary = Ary.del(); console.log(Ary);

@

JS 去除重復元素的方法