I am using React for this, but the concept is in javascript. So hopefully I can leave React code out for simplicity sake.
I have two arrays that I need to filter out. My goal is to map over an array and check if a property of that object matches a property in an object of the other array.
First array looks like this:
[{id: 1}, {id: 2}, {id: 3}, {id: 4}]
Second one looks like this:
[{id: 3}, {id: 4}]
So if one object has the same id property as an object in the other array, return a react element/anything.
Here is something I got to work, but it only goes through the index and compares them. This appears to loop over the 1st array properly, but I cant seem to loop over the second array by 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>
}
})