DEV Community


Posted on

For loop

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:
Alt Text
Let's see a pratical example.
I want to add this "✨" for each animal in my array.

let animals = [
Enter fullscreen mode Exit fullscreen mode

For loop makes my task easier like this:
Alt Text
Alt Text
Now let's try to create a new array with our animals plus a star for each one.
Alt Text

for loop how it works:
Alt Text
ES6 introduced for...of loop, the new loop sintax:
Alt Text
easy to read and maintain.

Top comments (0)