I have a question about filtering with ES6:
I have some data which I need to filter with other objects
My data is:
let data = [
{
id: 1,
names: ['A', 'B']
},
{
id: 2,
names: ['C']
}
]
I have another object as:
let nameValues = [
{
name: 'A',
selected: false
},
{
name: 'B',
selected: true
},
{
name: 'C',
selected: false
},
{
name: 'D',
selected: true
}
]
I'm first getting selected == true
items in selectedNames
with:
let selectedNames = nameValues.filter(function(item) {
return item.selected
})
and I'm getting result:
selectedNames = [
{
name: 'A',
selected: true
},
{
name: 'D',
selected: true
}
]
and I need to compare it with data
, getting items in data
where item.names
have selectedNames
in it.
I don't need exactly matching -- I need the items in data object which have in their names array my selectedNames
object name
values:
In this case I need to get like this result of my data object:
Here is item not matching 100% with my selectedNames
but it have one of these values which I am looking for
let data = [
{
id: 1,
names: ['A', 'B']
},
]
How to do that with es6?