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"]