根据数组中多个对象的值 进行去重处理

// tpTypeList 过滤掉其中相同时间重复的tp值
        if (res.data.tpTypeList && res.data.tpTypeList.length > 0) {
          const removeDuplicateObj = (arr) => {
          // 缓存用于记录
            const newArr = [];
            for (const t of arr) {
            // 检查缓存中是否已经存在
              if (
                newArr.find(
                  (c) =>
                    c.tpType === t.tpType &&
                  c.updateTime === t.updateTime
                )
              ) {
              // 已经存在说明以前记录过,现在这个就是多余的,直接忽略
                continue;
              }
              // 不存在就说明以前没遇到过,把它记录下来
              newArr.push(t);
            }
            // 记录结果就是过滤后的结果
            return newArr;
          };
          res.data.tpTypeList = removeDuplicateObj(res.data.tpTypeList);
        }
 
tpTypeList 过滤掉其中相同时间重复的tp值
 

 

posted @ 2022-12-29 17:21  樱花雨纷飞  阅读(41)  评论(0编辑  收藏  举报