I have a profileList array that the user should be able to filter. The filter applies to the "tags" nested array.
The user also creates a whitelist of tags that can be added to each profile (one or more tags) in the "tags" nested array.
The the user should be able to filter the profileList array by adding one or more tags to filterArray.
So my problem is to be able to check if at least one of the tags in the filterArray is included in the "tags" nested array within the profileList array.
The code below doesn't work obviously as the filter function checks if "all" filter tags are present in the profileList / tags array.
How can I write the filter function?
Any help much appreciated.
//the array to filter
let profileList = [
{name: "John", tags: ["green", "yellow", "red"]},
{name: "Alex", tags: ["yellow", "white", "purple"]},
{name: "Jane", tags: ["green", "pink", "blue"]}
]
//user defined: they can add up to 30 statuses
let taglist = ["green", "yellow", "red", "black"...]
//also user defined: they can filter by as many statuses as they want
let filterArray = ["green", "red"]
const filteredProfiles = store.state.profileList.filter(element => {
return filterArray.includes(element.tags);
});
//for ex. if the user decides to add "yellow" and "red" to the filterArray, then the function should return John and Alex
taglistis not usedtagList? Does it overridefilterArrayor does it merge with it?tagListis just an example of an array of tags i guess