Apologies if this has been asked before and if what I am asking doesn't make sense please let me know and I will do my best to clarify.
What I am looking for is a function that works the same way as the .includes() function does, but I would like it to accept an array. It seems that the "includes" function only looks for 1 needle in a haystack instead of multiple needles.
Any help with this would be great.
For Context: I am working in Vuejs, and I have a computed property that is taking an array of objects and each object contains another array of colors. To sort I am adding color codes to the selectedColors array and would like to filter my searchArray results based on the selectedColors array.
Below is what I have in my computed property as of now... and obviously when the selectedColors array has anything in it, no results are returned.
colorArray: function() {
return this.searchArray.filter(station => {
if (this.selectedColors) {
return station.colors.includes(this.selectedColors)
} else {
return this.searchArray
}
})
}
Here is an example of my searchArray:
this.searchArray: [
{title: 'first', colors: ['BL', 'YL']},
{title: 'second', colors: ['YL']},
{title: 'third', colors: ['OR', 'GR']},
]
Here is an example of my selectedColorsArray:
this.selectedColors: ['BL', 'YL']
Any help with this is greatly appreciated! Thanks