Array methods · 배열 메소드
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Array methods
.map(fn)makes a new array by transforming each item..filter(fn)makes a new array of only the items wherefnreturnstrue..forEach(fn)runsfnfor each item, making no new array.
한국어
배열 메서드
.map(fn)은 각 항목을 변환하여 새로운 배열을 만듭니다..filter(fn)은fn이true을 반환하는 항목만 포함하는 새로운 배열을 만듭니다..forEach(fn)는 각 항목마다fn를 실행하며, 새로운 배열을 만들지 않습니다.
let nums = [1, 2, 3];
let doubled = nums.map((n) => n * 2);
console.log(doubled); // → [2,4,6]
English
Filtering keeps some items
.filterkeeps each item for which the test returnstrue.
한국어
필터링은 일부 항목을 유지합니다
.filter은 테스트가true을 반환하는 각 항목을 유지합니다.
let nums = [3, 7, 2, 9];
let big = nums.filter((n) => n > 4);
console.log(big); // → [7,9]
English
Watch out
.mapand.filterreturn a new array — the original is untouched.- You hand each one an arrow function that says what to do with one item.
한국어
주의사항
.map과.filter은 새로운 배열을 반환하며, 원본은 변경되지 않습니다.- 각 항목에 대한 처리 방법을 명시하는 화살표 함수를 전달합니다.
English
Common mistakes
mapandfilterreturn a NEW array — they do not change the original.forEachjust loops and returns nothing.
한국어
흔한 실수
map과filter은 NEW(새로운) 배열을 반환하며, 원본을 변경하지 않습니다.forEach은 단순히 순환하고何も 반환하지 않습니다.
English
Now you try
- Use
.map,.filteror.forEach. - Press Check answer to test it.
한국어
이제 직접 해보기
.map,.filter또는.forEach을 사용하세요.- 답안 확인을 눌러 테스트해 보십시오.
Use .map to double every number in [1, 2, 3] and store the new array in result (it should be [2, 4, 6]). · .map를 사용하여 [1, 2, 3]의 모든 숫자를 두 배로 만들고, 그 결과를 새로운 배열 result에 저장하세요 (결과값은 [2, 4, 6]이어야 합니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use .filter to keep only the numbers greater than 4 from [3, 7, 2, 9, 1], in a variable big (it should be [7, 9]). · .filter를 사용하여 [3, 7, 2, 9, 1]에서 4보다 큰 숫자만 선택하여 변수 big에 저장하세요 (결과값은 [7, 9]이어야 합니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use .forEach to add every number in [4, 8, 15] to total (it should end up 27). · .forEach를 사용하여 [4, 8, 15]의 모든 숫자를 total에 추가하세요 (최종 결과값은 27이 되어야 합니다).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.