Javascript——Arayオブジェクトにプロトタイプ方法を追加し、配列の重さを実現します.


    var arr = [5, '5', 5, 2, "2", 2, 1, 3];

    //Array.prototype.     = function(){}
    Array.prototype.unique = function() {
        var obj = {}
        var newarr = []
        for (var i = 0; i < this.length; i++) {
            if (!obj[this[i]]) {
                obj[this[i]] = true;
                newarr.push(this[i]);
            }
        }
        return newarr;
    }
    console.log(arr.unique());