js 比较两个数组,取出比另一个数组多的数据

需求:有一个数组,需要找出比旧数组多的数据,删除的数据

    getNewValues(arr1, arr2) {
    
    
      let res = [];
      arr2.forEach((item, idx) => {
    
    
        if (arr1.indexOf(item) == -1) res.push(item);
      });
      return res;
    },

调用

  // 新增的列表
      let arr1 = _this.getNewValues(_this.oldList, arr);
      // 删除的列表
      let arr2 = _this.getNewValues(arr, _this.oldList);

猜你喜欢

转载自blog.csdn.net/L221545/article/details/132410678