So I want to filter an array of objects according to a few filters I have created:
items.filter(
(obj) =>
(!status || (obj.globalId && obj.globalId !== "")) &&
(!deletedSwitch || obj.deleted === deletedSwitch) &&
(!filteredUsername || obj.userId === userId) &&
(!filteredType || obj.type === filteredType) &&
(!filteredVariety || obj.variety === filteredVariety) &&
(!filteredSize || parseInt(obj.size) === filteredSize)
)
So as you can see, I filter the items based on a few properties. These properties are selected through a <select> component. status property used to be a boolean state where I want to check if the item has a globalId or not. However, now I want to change it in a way where I check if status is connected, then I want to filter all items that have a globalId each. But if the status is not connected, I want to filter all items that DO NOT have a globalId. How can I modify my code above to achieve this?