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

Converting Object to an Array

Converting Object to an Array

Spread Operator for Objects

Using the spread operator during an Object declaration will assign the properties of the referenced Object to the new Object.

jQuery on hover

Jquery on mouse over example.

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

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

try/catch es10

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