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

Async await in javascript

Async await in javascript

Lấy tháng hiện tại trong javascript

Lấy tháng hiện tại trong javascript

Calculate the number of difference days between two dates

Calculate the number of difference days between two dates

try/catch es10

An update for developer convience allows the use of try/catch without an explicit e Error reference in the catch call.

So sánh hai array trong javascript

Làm thế nào để đánh giá xem hai mảng có bằng nhau không? Có hai cách đó là sử dụng JSON.stringify() hoặc toString()