Consider the following arrays:
array1 = ["A","B", "C"];
array2 = ["D", "E", "F"];
array3 = ["G", "H", "I"];
combined = [array1, array2, array3];
select = ["A","H"];
I need a filter for 'combined' based on the 'select' array that returns array1 and array3 as A is in Array1, and H is in array3.
This is what I have tried (in typescript)
return routes.filter((route: any) =>
roles.some((role: string) =>
route.config.roles.some((routeRole: string) =>
routeRole === role)));
It seems to work, but it only works for the first item in the route.config.roles.
Use filter and some:
function finder(combined, select) {
return combined.filter(function (el) {
return el.some(function (letter) {
return select.indexOf(letter) > -1;
});
});
}
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With