How to filter the following array with another array values?
const GuideTabs = [
{ id: 0, label: 'Highlights', analyticsCategory: 'Highlights' },
{ id: 1, label: 'Labor & Employment', analyticsCategory: 'Labor & Employment' },
{ id: 2, label: 'Culture', analyticsCategory: 'Culture' },
{ id: 3, label: 'Holidays', analyticsCategory: 'Holidays' },
]
I want to filter this array with the following array to return only the existing data
const gtabs = ['Culture, Holidays']
const arr = GuideTabs.filter(function(item){
return gtabs.indexOf(item.id) === -1
})
But it returns all the 4 array item in GuideTabs all the time, But it should return 2,3 items from GuideTabs array
const GuideTabs = [
{ id: 0, label: 'Highlights', analyticsCategory: 'Highlights' },
{ id: 1, label: 'Labor & Employment', analyticsCategory: 'Labor & Employment' },
{ id: 2, label: 'Culture', analyticsCategory: 'Culture' },
{ id: 3, label: 'Holidays', analyticsCategory: 'Holidays' },
]
const gtabs = ['Culture, Holidays']
const arr = GuideTabs.filter(function(item){
return gtabs.indexOf(item.id) === -1
})
console.log(arr)
const gtabs = ['Culture, Holidays']this is an array with one element. I guess this should beconst gtabs = ['Culture', 'Holidays']return gtabs.indexOf(item.label) != -1?