Answer the question
In order to leave comments, you need to log in
What is the most efficient way to remove an object from an array in Vuex?
1 option
mutation(state, { id }) {
state.arr = state.arr.filter(item => item.id != id)
}
mutation(state, { id }) {
Vue.delete(state.arr, state.arr.findIndex(item => item.id == id))
}
Answer the question
In order to leave comments, you need to log in
Both options are about the same - the speed of searching for an index to delete will be O (N). The most efficient option is to use an object with id keys, then the lookup speed is O(1).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question