Let's say I have a data and a map.
let data = [
{
'name': 'bob',
'items': ['111']
},
{
'name': 'Jane',
'items': ['111']
},
{
'name': 'Greg',
'items': ['222']
}
]
let item_map = [
{ 'Item1': '111', 'Item2': '222'}
]
The items in data object contains the ids of the item.
What I am trying to do is to filter out the object from data where using a list of values matched to the id of the map.
For example, given ['Item1'], I want to get
[{
'name': 'bob',
'items': ['111']
},
{
'name': 'Jane',
'items': ['111']
}]
What I tried is
data.filter( item => ['111'].some(filter => (item_map["Item1"]).includes(filter)))
But this keeps giving me a Uncaught TypeError: Cannot read property 'includes' of undefined error.
EDIT
data.filter(item => ['111'].some(filter => item_map[0]["Item1"].includes(filter)))
This is what I newly tried, but this just returns all three items.
item_mapdoes not have an "Item1" property. It is an array, and its element is an object with that property.data. You don't actually use theitemyou get fromdata.