filter

Tags
테스트
변환
새로운 배열 생성
요약
특정 조건을 통과하는 요소만 모아서 배열로 반환
arr.filter(callback(element[, index[, array]])[, thisArg])
특정 조건을 통과하는 요소만 모아서 새로운 배열로 반환

인자

callback
: 각 요소를 시험할 함수. true를 반환하면 요소를 유지하고, false를 반환하면 버립니다. 다음 세 가지 매개변수를 받습니다.
element처리할 현재 요소.
index Optional처리할 현재 요소의 인덱스.
array Optionalfilter를 호출한 배열.
thisArg Optional
: callback을 실행할 때 this로 사용하는 값.
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present']; const result = words.filter(word => word.length > 6); console.log(result); // expected output: Array ["exuberant", "destruction", "present"]