배열삭제

728x90
반응형
·Node.js
우연히 some함수를 알게 되어서, filter와 비슷하여 비교글을 쓰고자 한다.1. filter()을 활용한 삭제const deleteNote = (id) => { const newNotes = notes.filter((note) => note.id !== id); setNotes(newNotes);}→ id를 prop으로 받아온다. notes배열에서 note.id가 파라미터로 일치하지 않는 원소만 추출하여 새로운 배열을 만든다. 이 말은 note.id가 id인 것을 삭제해준다. 처음에 이걸 이해를 못해서 많이 헤맸다.2. some()을 활용한 삭제const array = [1, 2, 3, 4, 5];const even = (element) => element % 2 === 0;console..
728x90
반응형
Uheeking
'배열삭제' 태그의 글 목록