javascript / beginner
Snippet
Iterating with for...of
The 'for...of' loop provides a clean and easy way to iterate over elements in an array or other iterable objects.
snippet.js
1
2
3
4
5
const fruits = ['Apple', 'Banana', 'Cherry'];for (const fruit of fruits) {console.log('I like ' + fruit);}
Breakdown
1
for (const fruit of fruits)
Assigns each element of the array to the variable 'fruit' one by one.
2
console.log(...)
Executes this block for every item found in the array.