DEV Community

GiandoDev
GiandoDev

Posted on

1

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
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.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay