JS - deleting targeted item from Array

suyeon·2023년 6월 21일
0

Vanilla.js

목록 보기
13/13
post-thumbnail

Array.filter()

: 이 메서드는 주어진 함수 테스트를 통과하는 (배열의) 모든 요소를 모아 새로운 배열을 생성 하여 반환함.

⚠️ 새로운 배열을 생성하기 때문에 이전의 배열을 변형하는 것이 아니다(필터 이전 배열과 새로운 배열이 동시에 존재 함).

//syntax
Array.filter(필터용 함수);

//example
const list = ["a", "b", "c", "d"];

function eraseB (alphabet) {
  return !== "b";
}

list.filter(eraseB);
// (3) ["a", "c", "d"]

console.log(list);
// (4) ["a", "b", "c", "d"]

profile
coding & others

0개의 댓글