forEach

Tags
반복문
요약
배열 각 요소 참조
arr.forEach(callback(currentvalue[, index[, array]])[, thisArg])
 
1) callback Required
: 각 요소에 대해 실행할 함수. 세 가지 매개변수를 가짐.
  • currentValue처리할 현재 요소.
  • index Optional처리할 현재 요소의 인덱스.
  • array OptionalforEach()를 호출한 배열.
2) thisArg Optional
: callback을 실행할 때 this로 사용할 값.
 

 
마지막의 thisArg는 다소 생소했는데, 콜백함수에서 this로 쓸 값을 지정할 수 있다.
다만 콜백함수에 화살표 함수를 넣으니까 thisArg가 제대로 동작하지 않았음.
notion image
 
notion image