I have an array of objects in this format:
var full_list = [
{
"pid": 1,
"items":[
{"item_id": '9'},
{"item_id": '10'},
{"item_id": '12'}
]
},
{
"pid": 2,
"items":[
{"item_id": '33'},
{"item_id": '22'},
{"item_id": '65'}
]
}...
];
I have a tmp array which consists of objects from the full array:
var tmp_list = [
{
"pid": 2,
"items":[
{"item_id": '33'},
{"item_id": '22'},
{"item_id": '65'}
]
}, {....}
I would like to filter out objects from the full list where at least one of selectedIDs values appears in the object's item's id array
var selectedIDs = {'1', '9', '45', ....};
and then add them to the tmp list.
I tried using filters but I failed to figure it out completely.
Thank you.
selectedIDs.forEach(function(id) {
var tmp = full_list.filter(function (obj) {
obj.items.forEach(function (item) {
if (item.id === id) {
console.log('found');
}
});
});
tmp_list.push(tmp);
});