I'm currently working with React, but the concept is based on Javascript. So, for simplicity's sake, I'll omit the React code.
I have two arrays that need filtering. My aim is to iterate over one array and compare a property of each object with a property in objects from the second array.
The first array appears as follows:
[{id: 1}, {id: 2}, {id: 3}, {id: 4}]
While the second one looks like this:
[{id: 3}, {id: 4}]
If an object has the same id
as an object in the other array, then return a React element or anything else.
I managed to make the following work, but it only compares by index. It seems to loop over the first array correctly, but I'm unable to iterate over the second array using anything other than the index.
return arr1.map((e, i) => {
return if (e.id === arr2[i].id) {
return <div>Match</div>
} else {
return <div>No Match</div>
}
})