I'm writing a filter to show only certain elements based on keywords. So I have an array of objects in this key/pair format:
name: "Accounting (AAS) | Business, Design & Hospitality Pathway",
type: "associate of arts",
method: "classroom based",
location: "centennial campus",
pathway: "business, design, & hospitality",
time: "4 semesters",
transfer: "transferable"
I have an object I'm creating from the radio buttons. It's called selectedFilters. If only one radio is checked it would return this:
{type: 'associate of arts'}
If two radios are checked:
{type: 'associate of arts', method: 'hyflex class'}
So the second object doesn't have all the properties of the first object. I need to check if the properties they do have in common match. So if the object created by the radio buttons has two properties. I only want the objects to return if both properties match.
I have an if statement in my forEach loop. But it only returns if every property matches. Can someone find a solution so I'm only pushing the objects where the properties that exist match?
data.forEach(function(el) {
if (
el.type == selectedFilters.type &&
el.method == selectedFilters.method &&
el.location == selectedFilters.location &&
el.pathway == selectedFilters.pathway &&
el.time == selectedFilters.time &&
el.transfer == selectedFilters.transfer
) {
result.push(el);
};
});