Hi so we are going to discuss about another loop statement. That
is for in loop statement. You may wonder why I haven’t discussed about for in
loop in simultaneously with other for loop.
The reason is we must have an idea about objects in java
scripts.
Ok lets’ go to the lesson.
This loop is go through the object properties. So this is
very useful loop.
The syntax is,
for(variablename in object){
statement
}
statement
}
So let’s see an example.
This prints the web browser’s Navigator object.
Figure 1
Figure 2
Let’s try with different object.
<script>
function
myFunction() {
var me = {fname:"Chamini",
lname:"Prashakthi"};
var word = "";
var x;
for (x in me) {
word += me[x] + " ";
}
document.getElementById("demo").innerHTML
= word;
}
</script>
This will produce output as : Chamini
Prashakthi
That is for in loop in js and
Thank you !👍
I'm very much inspired when I've visited your blog. your blog is very nice and informative! Hope. Thanks for share how to used "For in loop in js".
ReplyDeleteMath Curriculum