diff --git a/src/helpers/find.ts b/src/helpers/find.ts new file mode 100644 index 000000000..58ed77900 --- /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 32e8dd725..02f5b824f 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