JS去重复

 <#--去重复-->
        Array.prototype.unique = function () {
            var res = [];
            var json = {};
            for (var i = 0; i < this.length; i++) {
                if (!json[this[i]]) {  //json中不包含第一个值,并放入json中,包含则跳出
                    res.push(this[i]);  //不包含的值放入res
                    json[this[i]] = 1;  //
                }
            }
            return res;
        }

datas.unique()

猜你喜欢

转载自chendaiming.iteye.com/blog/2271953
今日推荐