Answer the question
In order to leave comments, you need to log in
Filtering an array for matches?
let arr1 = [ ["british", "classic-rock"], ["pop"], ["rock", "classic-rock"] ]
let arr2 = ["british", "pop"]
[ ["british", "classic-rock"], ["pop"] ]
Answer the question
In order to leave comments, you need to log in
const groups = [
["british", "classic-rock"],
["pop"],
["rock", "classic-rock"],
];
const filterKeys = ["british", "pop"];
groups.filter((g) => filterKeys.some((k) => g.includes(k)))
Understood nothing. Why did you take classic-rock into the final array in the first example , and decided to discard it in the second?
Most likely, the .filter() method will suit you . You simply check through this method each element of the array for the presence in the selected ones.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question