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);
});