• JavaScript数组去重


    /// <summary>
    /// 数组去重
    /// </summary>
    /// <param name="fieldName">去重的字段名</param> 
    Array.prototype.distinct = function (fieldName) {
        var arr = this;
        var uniqueArr = [];
        var includedKey = {};
        for (var i = 0; i < arr.length; i++) {
            var value = arr[i][fieldName];
            if (includedKey[value]) continue;
            uniqueArr.push(arr[i]);
            includedKey[value] = 1;
        }
        return uniqueArr;
    }
    // 测试
    var test = [{ id: '1' }, { id: '2' }, { id: '2' }, { id: '1' }, { id: '3' }];
    test = test.distinct('id');
    alert(JSON.stringify(test));
  • 相关阅读:
    8.26 树状数组
    8.27 神异之旅
    8.26 雇佣
    8.28 Jack与Rose
    8.28 ISN
    保存和加载网络
    快速搭建网络
    分类网络
    torch中的回归
    pytorch中的Variable
  • 原文地址:https://www.cnblogs.com/jh007/p/6179202.html
Copyright © 2020-2023  润新知