I'm trying to filter the array here but the result seem to be empty. How do I loop through inner array in a filter function?
Below is the snippet
const carIds = ['100', '101'];
const carsList = [{
name: 'BMW',
id: '100'
}, {
name: 'Jeep',
id: '101'
}, {
name: 'Audi',
id: '103'
}];
const result = carsList.filter((val) => val.id === carIds.map((val) => val))
console.log('result', result)
Expected output should be
[{
name: 'BMW',
id: '100'
}, {
name: 'Jeep',
id: '101'
}]
Could anyone please advise?
map()returns an array. How canval.idbe equal to an array?