javascript

for of loop javascript

for of loop javascript

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 = [...restaurant.starterMenu,...restaurant.mainMenu];
console.log(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}`)
};
//Output:
/* 1:Focaccia
2:Bruschetta
3:Garlic Bread
4:Caprese Salad
5:Pizza
6:Pasta
7:Risotto */

 Conclusion:

 

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 suggestion then please inform us by commenting.

Don’t forget to share this tutorial with your friends on facebooktwitter 

 

 

 

 

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