JavaScriptArrayforEach

Executes a provided function once for each array element.

Syntax

arr.forEach(callbackFn)

Example

Enter values below to update the example in real time.

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