筛选出两个数组不相同的元素

let a = [{ name: 'javascript', id: 0 }, { name: 'css', id: 1 }, { name: 'html', id: 2 }]
let b = [{ name: 'css', id: 1 }, { name: 'html', id: 2 }]
let n = [];
for (let i = 0; i < a.length; i++) {
  let staA = a[i].id;
  let sta = 0;
  for(let j = 0; j < b.length; j++){
    let staB = b[j].id;
    if (staA == staB){
      sta++
    }
  }
  if (sta == 0){
    n.push(a[i])
  }
}
console.log(n)

  

posted @ 2020-07-20 17:57  zshNo1  阅读(571)  评论(0编辑  收藏  举报