I have 2 data sets:
People:
[
{id:1, selected:[1,2,3,4]},
{id:2, selected:[1,2,3,4,5]},
{id:3, selected:[11]},
{id:4, selected:[1,2,5]}
]
selectedArray:
[1,2,3]
I can filter People.id by selectedArray:
_(People).indexBy('id').at(selectedArray).value();
But I'm stumped on how I would filter for a field that is not represented as a single value. eg. People[0].selected which is an array of integers.
Is it possible to only show People objects that contain at least 1 integer in the People selected field from selectedArray?
I tried this:
_.intersection(selectedArray, _.map(People, 'selected'));
I eventually want to have a People object array with a selected field which is limited to the integers of selectArray. So the result would be:
[
{id:1, selected:[1,2,3]},
{id:2, selected:[1,2,3]},
{id:4, selected:[1,2]}
]
I'm currently going through a for loop to calculate this but I don't think it's a very good solution and I'm wondering if there's a more elegant approach than traversing through the entire object array.