数组去重的方法

    //数组去重  
Array.prototype.unique = function() {
    //通过对象属性名不能重复特性
    var arr = [],
        temp = {},
        len = this.length;
    for (var i = 0; i < len; i++) {
        //如果temp里的
        if (!temp[this[i]]) {
            temp[this[i]] = "abc";
            arr.push(this[i]);
        }
    }
    return arr
}
 
//数组去重
Array.prototype.unique1 = function() {
    return [...new Set(this)]
};
posted @ 2021-03-10 13:41  刘雨鑫  阅读(55)  评论(0)    收藏  举报