filter() 함수는 주어진 함수의 테스트를 통과하는 모든 요소를 모아 새로운 배열로 반환하는 함수이다.
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"]
filter를 이용하여 words데이터 중에서 길이가 6보다 큰 데이터를 result에 담아 출력을 할 수 있다.
조건에 맞는 값만 출력을 할 때 사용을 하면 된다.
'Programming > Front-end Language' 카테고리의 다른 글
[React] useEffect 사용법 (0) | 2022.03.23 |
---|---|
[React] React로 Voca 만들기 -2 (0) | 2022.03.23 |
[React] Map() 함수를 이용한 반복 (0) | 2022.03.23 |
[React] React로 Voca 만들기 -1 (0) | 2022.03.23 |
[React] React Hooks - useState 사용법 (0) | 2022.03.22 |