How to loop an array?

const words = ['Hallo Welt', 'Nani?', '42']

// output: Hallo Welt 0, Nani? 1, 42 2
words.forEach((word, index, array) => {
  console.log(word, index)
})
Copy

September 6th, 2019

# forEach() - Looping an array

Add to bookmarks

Provide forEach() a callback function and it will apply it on each element in ascending order.

Tracking with Matomo to improve the UX. See Privacy Policy for more details.