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

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

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

Remove item in array javascript es6

Những bạn nào mà đã sử dụng ES6 một thời gian rồi thì có thể sử dụng method array.filter()

serialize Form

Sử dụng formdata constructor để convert form, FormData, array.from(). Kết hợp window.encodeURIComponent() để encode từng value trong form.

Ajax, call jQuery POST to node.js expressjs

Ajax, call jQuery POST to node.js expressjs

Đếm có bao nhiêu items giống nhau trong một array

reduce javascript. Đếm có bao nhiêu items giống nhau trong một array