.forEach()

.forEach()

  • Method allows us to run a callback function for every element of the array

  • The callback function for forEach provides the following:

    • element - this current element from the array that is being evaluated

    • index - this represents the current element’s index (or position in the array)


Example

const chipmunks = ["alvin", "simon", "theodore"]

chipmunks.forEach((element, index) => {
  console.log(`${element} is at index ${index}`)
})

JS Bin on jsbin.com