I am trying to apply filter option from an array.
options = [
"car",
"bike",
]
I have multiple filter select, that's why using an array to contain more then one option.
and let's say there is array that I want to filter.
array = [
"car",
"fruit",
"keyboard",
"computer"
]
if the option is string like options = "car"
then the thing is very easy
if (!options.length) {
return array;
} else {
return array.filter(item => {
return item === options;
})
}
But the thing is how can I handle if the options
is not string
but an array?
For example I tried to put filter function inside for loop.
let len = options.length
console.log(len)
for (let i = 0; i < len; index++) {
return array.filter(item => {
return item === array[i];
})
}
but it didn't worked out. It's only taking first selected from an array.