javacript的Array 去除重复项

去除数组中重复的对象。
Array.prototype.getUnique = function() {
        var hash = {}, result = [], key; 
        for ( var i = 0, l = this.length; i < l; ++i ) {
            key = JSON.stringify(this[i]);
            if ( !hash.hasOwnProperty(key) ) {
                hash[key] = true;
                result.push(this[i]);
            }
        }
        return result;
    }

 

posted @ 2017-07-19 11:54  baoged  阅读(90)  评论(0编辑  收藏  举报