map(2)
-
[Javascript] map()과 filter()의 차이 이해하기
map()과 filter(). 둘은 매우 비슷하게 생겼다. 콜백 함수의 인자도 거의 똑같고 생김새까지도. 다만 각 함수는 return하는 기능이 다르다고 할 수 있다. map()callback 함수를 각각의 요소에 대해 한 번씩 순서대로 불러 그 함수의 반환 값으로 새로운 배열을 생성.arr.map(callback(currentValue[, index[, array]])[, thisArg]) callback은 새로운 배열 요소를 생성하는 함수로 다음 세 가지 인수를 가진다.currentValue: 처리할 현재 요소index(Optional): 처리할 현재 요소의 인덱스array(Optional): map()을 호출한 배열thisArg(Optional): callback을 실행할 때 this로 사용할 값..
2025.07.10 -
[Javascript] 배열 내장 함수 정리(forEach, map)
forEach 구문 일반 for문 사용 const animals = ['호랑이', '사자', '사슴', '토끼', '거북이']; for (let i = 0; i < animals.length; i++) { console.log(animals[i]); } forEach 사용 const animals = ['호랑이', '사자', '사슴', '토끼', '거북이']; function print(animal) { console.log(animal); } animals.forEach(print); forEach 및 익명 함수 사용 const animals = ['호랑이', '사자', '사슴', '토끼', '거북이']; animals.forEach(function(animal) { console.log(animal)..
2020.08.14