js 比较两个数组对象,取不同的值

 

let array1 = [
      {'Num': 'A ', 'Name': 't1 '},
      {'Num': 'B', 'Name': 't2'},
      {'Num': 'C ', 'Name': 't3 ', age: '222'},
      {'Num': 'D', 'Name': 't4 ', age: '3333'}
    ];

let array2 = [
      {'Num': 'A '},
      {'Num': 'B'}
];

let result = [];
for (let i = 0; i < array1.length; i++) {
      let isExist = false;
      for (let j = 0; j < array2.length; j++) {
        if (array1[i].Num === array2[j].Num) {
          isExist = true;
          break;
        }
      }
      if (!isExist) {
        result.push(array1[i]);
      }
}

  

posted @ 2021-10-08 16:16  PromiseOne  阅读(1693)  评论(0编辑  收藏  举报