0

Say I have an array A like this:

A: [{name: "Caitlyn", type: "Teacher"}, {name: "John", type: "Student"},{name: "Rob", type: 
"Student"},{name: "Jessica", type: "Librarian"},{name: "Kevin", type: "Janitor"}]

And array B:

B: [{name: "Rob", type: "Student"},{name: "Jessica", type: "Librarian"}]

My expectation is elements in array B that are also in array A will be removed in array A:

A: [{name: "Caitlyn", type: "Teacher"}, {name: "John", type: "Student"}, {name: "Kevin", type: "Janitor"}]

I first used includes something along the line of:

a.filter((item) => !b.includes(item));

But it does not achieve what I want. I also tried includes from lodash but I only attempt to do this and the result comes out false:

includes(a,b) //=> false

I am currently looking into find from lodash. Helps will be appreciated. Thank you!

Noelia
  • 89
  • 9

0 Answers0