Frontend/자바스크립트 Java Script

splice(start, count, 대체내용들)

Study-note 2020. 8. 18. 14:44

splice(start, count, 대체내용들) 시작위치부터 count 갯수만큼 추츨해낸 후 세번째 인자인 대체내용들로 해당위치를 채워 넣음

 

splice(1, 3, 'a', 'b', 'c') 첫번째부터 세개 빼고 a, b, c를 채워 넣음

 

// mutation에 import한 경우 []로 감싸줘야한다.(문법오류 방지)

[REMOVE_TODO] (state, id) {

    const targetIndex = state.todoItems.findIndex(v => v.id === id)

    state.todoItems.splice(targetIndex, 1)

},