The JavaScript for…in loop is used to iterate over properties of Objects. In JavaScript, Arrays are also Objects and each character in a string have an index. So, we can use them also to iterate over Arrays and Strings.
//Object example const obj = { a: 1, b: 2, c: 3, d: 4 } for (const key in obj) { console.log( obj[key] ) }
// Output:
1 2 3 4 //Array example const array = ['a', 'b', 'c', 'd']; for (const index in array) { console.log(array[index]) }
// Output:
a b c d //String example const string = 'Web Developer'; for (const index in string) { console.log(string[index]) }
//Output:
W e b D e v e l o p e r
I have learned many things from this article. It is beneficial for me. Thank you!
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!
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 *