Remove array of objects from another array of objects

function,object,array,es6

Remove array of objects from another array of objects

var a = [{
  'id': '1',
  'name': 'a1'
}, {
  'id': '2',
  'name': 'a2'
}, {
  'id': '3',
  'name': 'a3'
}]
var b = [{
  'id': '2',
  'name': 'a2'
}]

var c = a.filter(function(objFromA) {
  return !b.find(function(objFromB) {
    return objFromA.id === objFromB.id
  })
})

console.log(c); [ {'id':'1', 'name':'a1'}, {'id':'3', 'name':'a3'}]

Có thể bạn đã miss một số snippets code

using async/await to catch errors

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

Using promises to catch errors

Promise.all là gì?

Promise.all là gì? Hiểu và sử dụng promise all trong những trường hợp nào trong vòng 1 phút.

Kiểm tra phần tử trùng trong mảng JavaScript

Kiểm tra phần tử trùng trong mảng JavaScript.