Higher Order Functions

forEach Visits Each Item

forEach Visits Each Item

forEach runs a callback once for every item in an array. It is useful when the main result is a side effect, such as logging, sending analytics, or updating something outside the array.

The callback receives the current item each time it runs. The array keeps its order, so the first callback call sees the first item.

Your task: Use forEach to log each name in learners. Log one name per callback run, and keep the original array unchanged.

Prerequisites

  • arrays
  • functions

Tests

  • forEach is used to visit the learners
  • each learner name is logged in order
  • the original learners array is unchanged
Loading...
Console

Run code to see output.

Previous1 / 56Next