ABOUT

성능과 운영 안정성을 함께 끌어올리는 개발자입니다.

92% Positional Error Reduction
79% p95 Latency Improvement
90%+ Long Tasks Reduction

2022.02 · 한국장학재단

우수 멘티

한국장학재단 사회 리더 대학생 멘토링 IT

2022.10 · 동작구청

우수 인재상

동작구청 우수 SW 인재

2025.05 · (주) 그랩

프로그래밍 우수상

(주) 그랩 우수 프로그램 개발

2025.05 · AWSKRUG

AWS한국사용자모임 발표

AI agent 스크립트 튜닝 관련 발표

ComputerScience

Development

Engineering

Trouble Shooting

GUESTBOOK

첫 마음부터
함께 나누는 온기

방명록 작성하러 가기

SUBSCRIBE

최신소식을
편하게 만나보세요.

filter( )

 

 

What ?

filter( )

배열의 얕은 복사본 을 만들고, 함수의 조건 에 맞는 요소 로만 필터링하는 함수


 

💡  형태

filter( callbackFn, thisArg )


💡
매개변수

요소 명 설명
callbackFn ( 필수 ) - Array ( 배열 ) 내 각 요소에 적용할 함수로 다음 인수를 통해 호출

- 인수 종류

 1. element : 처리중인 배열 내 요소

 2. index : 처리중인 배열 내 요소의 인덱스

 3. array : filter() 가 호출된 배열 자체
thisArg ( 선택 )   callbackFn 실행 시,  this  으로 사용할 값

 

 


 

 

How ?

const example = ['test', 'enchantment', 'tstory', 'subscribe'];

// word(인자)는 element 입니다.
const elementExample = example.filter((word) => console.log(word));
// index(인자)는 index 입니다.
const indexExample = example.filter((word,index) => console.log(index)); 
// arr(인자)는 array 입니다.
const arrayExample = example.filter((word,index,arr) => console.log(arr));
// 활용법
const result = example.filter((word) => word.length > 6);

console.log(elementExample);
console.log(indexExample);
console.log(arrayExample);
console.log(result);

 

💡 elementExample 결과

> "test"
> "enchantmetn"
> "tstory"
> "subscribe"
> Array []

 

💡 indexExample 결과

> 0
> 1
> 2
> 3
> Array []

 

 

💡 arrayExample 결과

> Array ['test', 'enchantment', 'tstory', 'subscribe']
> Array  ['test', 'enchantment', 'tstory', 'subscribe']
> Array  ['test', 'enchantment', 'tstory', 'subscribe']
> Array  ['test', 'enchantment', 'tstory', 'subscribe']
> Array []
> Array ["exuberant", "destruction", "present"]

 

💡 result 결과

> Array ["exuberant", "destruction", "present"]

 

 


 

 

브라우저 호환성

 


 

728x90