I'm trying to filter an array of objects to return only the objects that match items in a second array and I can't seem to get it to work.
export const Config = [
{
labels: ['label_1', 'label_2', 'label_3'],
title: 'Home',
link: '/',
},
{
labels: ['label_1'],
title: 'One',
link: '/one/',
},
{
labels: ['label_2'],
title: 'Two',
link: '/two/',
},
{
labels: ['label_3'],
title: 'Three',
link: '/Three/',
},
]
const filters = [
"label_1",
"label_2"
]
const filterdLabels = config.filter(item => {
return filters.forEach(filter => {
return item.labels.includes(filter)
})
})
This is my code, I would expect that filtered labels is an array of any objects that have the matching labels in the labels array.
Any ideas?
Thanks
Via Active questions tagged javascript - Stack Overflow https://ift.tt/LOBHu5m
Comments
Post a Comment