JavaScript배열forEach

forEach배열

각 요소에 대해 함수를 실행합니다.

문법

arr.forEach(callbackFn)

예제

아래 값을 입력하면 예제에 즉시 반영됩니다.

const
fruits
forEach
fruit
index
console
const fruits = ["apple", "banana", "cherry"];
fruits.forEach((fruit, index) => {
  console.log(`${index}: ${fruit}`);
});