diff --git a/src/helpers/find.ts b/src/helpers/find.ts new file mode 100644 index 00000000..58ed7790 --- /dev/null +++ b/src/helpers/find.ts @@ -0,0 +1,3 @@ +export function findIndexById(array : [], id : string | number) { + return array.findIndex(({id: currentId}) => currentId === id) +} \ No newline at end of file diff --git a/src/store/modules/attachments.js b/src/store/modules/attachments.js index 32e8dd72..02f5b824 100644 --- a/src/store/modules/attachments.js +++ b/src/store/modules/attachments.js @@ -1,5 +1,7 @@ import Vue from 'vue' +import {findIndexById} from '@/helpers/find' + export default { namespaced: true, state: () => ({ @@ -15,13 +17,9 @@ export default { state.attachments.push(attachment) }, removeById(state, id) { - for (const a in state.attachments) { - if (state.attachments[a].id === id) { - state.attachments.splice(a, 1) - console.debug('Remove attachement', id) - break - } - } + const attachmentIndex = findIndexById(state.attachments, id) + state.attachments.splice(attachmentIndex, 1) + console.debug('Remove attachement', id) }, }, } \ No newline at end of file