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

How to use the spread operator to flatten array of objects in javascript

How to use the spread operator to flatten array of objects in javascript

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.

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

Async await in javascript

Async await in javascript

Copy a string to the clipboard

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).