js ForEach 반복문

석현정·2022년 12월 13일
0

ForEach

forEach()는 배열 활용익 가능한 메서드로, 파라미터로 주어진 함수를 배열 요소 각각에 대해 실행하는 메서드이다.
map()메서드와 거의 비슷하지만 차이점은 따로 return하는 값이 없다는 점.

const myArr = [1, 2, 3, 4, 5];

myArr.forEach((currentElement, index, array) => {
    console.log(`요소: ${currentElement}`);
    console.log(`index: ${index}`);
    console.log(array);
});

//결과값

*출처
https://bigtop.tistory.com/58

profile
온전히 나를 위한 코딩 기록 공간

0개의 댓글