So, I have 3 filter boxes. The first is named room, second is named color and the third is named staff.
For every filter box there are multiple values which I can choose, for example for color I can choose the value "blue" or for room "presidential". I pass the name of the filterbox and the chosen value in a function changeBox (for example name: color, value: blue).
With that information I want to filter an array. Of course I want to have multiple filters active, which only show the wanted results which are compatible to my activated filters.
So what I did was using a switch case for every possibility which looked like this:
changeBox(name, value) {
if (name === "color") {
switch (value) {
case "blue":
myArray = myArray.filter(item => item.color === "blue");
break;
}
}
if (name === "room") {
switch (value) {
case "presidential":
myArray = myArray.filter(item => item.room === "presidential");
break;
}
}
}
This works If I have only one filter active. The problem is now, if I activate a second filter it works too. But if I switch the second filter to another value, it doesn't work. I know it's because of the myArray.filter. It deletes every value in the array which doesn't fit to my filter. How can I keep the data without actually overwrite it every time?