How to loop an array with `for...of`?

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

// for-of loop
// output: Hallo Welt 0, Nani? 1, 42 2
for(const [index, word] of words.entries()) {
  console.log(word, index)
}
Copy

September 2nd, 2019

# for...of - Looping an array

Add to bookmarks

for...of will execute statements on each value. Can be used for so-called iterable objects.

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