For example, how do I check if ALL the objects in array2
exist in array1
based on their id
?
const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }]
const array2 = [{ id: 1 }, { id: 2 }]
For some reason, I couldn't find the solution on Google.
I thought about this:
const result = array1.every(obj1 => {
// what do use here? includes? contains?
})
console.log(result)
But I'm kind of stuck in the middle of the code. The most logical solution to me was to use includes
. However, includes
doesn't seem to take a function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes. So I'm not sure if I can check the objects by id.