Introduction to JavaScript for…of Loop in ES6

Introduction to JavaScript for…of Loop in ES6

In this tutorial, we will learn about for of loop in javascript.

So let's get started...

What is the For...of Loop?

For...of loop was introduced in ES6 which iterates over iterable such as Arrays, strings, Maps, Sets, and more. 

Looping through Array:

const menuArr = [,];

for(const item of menuArr) console.log(item);
//Getting Index with array element
for(const item of menuArr.entries()) {
  console.log(`${item[0] + 1}:${item[1]}`)
//Using destrcreing
for(const [i,el] of menuArr.entries()) {
  console.log(`${i + 1}:${el}`)
/* 1:Focaccia
3:Garlic Bread
4:Caprese Salad
7:Risotto */


Thanks for reading.

Do let me know If you face any difficulties please feel free to comment below we love to help you. if you have any feedback suggestions then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook, Twitter 

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment