Most of the time we will have to iterate through an array or an object, so I will use an array for examples.
Anatomy of a for loop:
Let's see a pratical example.
I want to add this "✨" for each animal in my array.
let animals = [
'🐶',
'🐼',
'🐸',
'🐥',
'🦄',
'🦋'
]
For loop makes my task easier like this:
Result:
Now let's try to create a new array with our animals plus a star for each one.
for loop how it works:
ES6 introduced for...of loop, the new loop sintax:
easy to read and maintain.
Top comments (0)