Looking for a solution to successfully filter an array of objects by comparing it to another array through looping over its values. The issue arises when the filter function stops at the first false, preventing the full comparison.
Any suggestions on how to work around this?
In the code below, simplified arrays and objects are used for demonstration:
const jobs = [
{id: 1,
location: 'AA'},
{id: 2,
location: 'BB'},
{id: 3,
location: 'CC'},
]
const filteredLocations = ['AA', 'CC']
const filteredJobs = jobs.filter(function(el, i) {
do {
return el.location === filteredLocations[i];
}
while (filteredLocations.length >= i)
})
// Only returns the first object instead of the desired first and third
Thank you!