On a Getter I need to filter an array and return values that match 2 conditions. I need to return item_categories that don't have an item_category_location equal to current location or don't have item_category_locations at all.
unaddedItemCategories(state, getters, rootState) {
let otherLocations = state.item_categories
.filter((item_category) =>
item_category.item_category_locations.some((item_category_location) => item_category_location.location_id !== rootState.currentLocation.id))
let noLocations = state.item_categories
.filter(item_category => item_category.item_category_locations.length == 0)
return otherLocations, noLocations
},
The 2 filters work fine. How can I chain them to create a new array?
You can do it like so:
return [...otherLocations, ...noLocations]