loading...

For loop

giandodev profile image GiandoDev ・1 min read

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 = [
  '🐶',
  '🐼',
  '🐸',
  '🐥',
  '🦄',
  '🦋'
]

For loop makes my task easier like this:
Alt Text
Result:
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.

Posted on May 4 by:

giandodev profile

GiandoDev

@giandodev

Hi, I am Giandomenico. I love to learn new stuff and solve problems.

Discussion

markdown guide