배열 내장함수 forEach

Clém·2020년 12월 23일
0
post-thumbnail

forEach

const animals = ["강아지", "고양이", "오리", "말"];

for (let i = 0; i < animals.length; i++) {
  console.log(animals[i]);
}

for문의 조건문을 일일이 작성하는 방법도 있지만

animals.forEach(function (animal) {
  console.log(animal);
});

내장함수를 사용하는 방법도 있다.
아래는 더욱 간결하게 작성한 코드이다.

animals.forEach((animal) => {
  console.log(animal);
});
profile
On my way to become a Web Publisher

0개의 댓글