The for…of loop was introduced in ES6 and is used to iterate over anything that has [Symbol.iterator] property. This includes array, strings and NodeList. They cannot be used to iterate over Objects are not iterable.
If we check the __proto__ of an array, we can find the [Symbol.iterator] property.
But it is not the case with Objects as it is not iterable.
//Array example const array = ['a', 'b', 'c', 'd']; for (const item of array) { console.log(item) }
// Output:
a b c d
//String example const string = 'Web Developer'; for (const character of string) { console.log(character) }
//Output:
W e b D e v e l o p e r //NodeList example const elements = document.querySelectorAll('.foo'); for (const element of elements) { element.addEventListener('click', doSomething); }
Nice example for beginners.. I m a beginner so this is very helpful for me ... so plz give this type of beginners example..
This is a great introduction to variables in JavaScript! As a beginner to JavaScript, I found this guide very helpful in understanding the basics of variables and how they are used in JavaScript.
Thanks for sharing the information, it is very helpful, I hope to get more such beautiful blogs from you.
You have shared great information with me i appreciate your work!
The tutorial provides the more information JavaScript this provides the end to end information about JS and also they provides the more detailed concepts of loops, functions, objects, arrays this will use us to buld the effective web site. Thanks for the team good job.
Build various types of web applications,command-line application,etc....
Introduction: Angular (What is Angular?)Angular was formerly introdu...
Leave a Reply
Your email address will not be published. Required fields are marked *