JavaScript配列forEach

各要素に対して関数を実行します。

構文

arr.forEach(callbackFn)

使用例

下記の値を入力するとサンプルに即時反映されます。

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