After searching for a solution to my specific case, I couldn't find one among similar questions. So, I apologize if this seems like a duplicate.
I'm currently working on creating a filter for my website and have encountered an issue regarding marker objects and their corresponding array of tags (referred to as 'types').
Essentially, when a user selects certain types of markers to display, these choices are stored in a 'selectedFilters' array as strings. My goal is to only show the markers whose types match those selected by the user. In other words, any marker object that contains at least one selected type in its 'types' array should be displayed.
const markers = [
{
type: ['Paper', 'Plastic']
},
{
type: ['Burnable', 'Plastic']
}
{
type: ['NotBurnable']
}
.
.
.
]
const selectedFilters = ['Burnable', 'Plastic']
const filteredMarkers = ????
My approach involves using the filter method along with some techniques to compare each object's types array with the selected filters and return only the matching objects. While I've managed to achieve this with a hardcoded string, I am struggling to implement it with an actual array:
const filteredMarkers = this.markers.filter(
marker => marker.type.some( type => type == 'Plastic')
)
I would greatly appreciate any advice, tips, or suggestions on how to dynamically replace the hardcoded string with the actual array and iterate through it effectively. Is there a different approach to building filters in a vue project?