Despite the multitude of discussions on this topic, I have not been successful in using the Array.filter
method to remove an item from a string-based Array. Below is an example of the filter method being used in the context of mutating a Vuex store.
UPDATE_FILTERS_GEOLOGIES: (state, payload) => {
if (state.filters.geologies.some(elem => elem === payload)) {
state.filters.geologies.filter(elem => !elem.includes(payload))
} else {
state.filters.geologies.push(payload);
}
}
Even though the filter method is called, the item is not removed. I resorted to using the Array.splice
method instead:
let position = state.filters.geologies.indexOf(payload);
state.filters.geologies.splice(position, 1)
I am unsure of what I may be doing incorrectly. Can someone please provide guidance?