Tech Junkie Blog: JavaScript Basics : The for/in Loop

Monday, April 24, 2017

JavaScript Basics : The for/in Loop

The for/in loop is a for loop that is used to iterate through the variables in an object. It can iterate to through that anything that can evaluated on the left side of the assignment expression call the LValues.  Let's use the for/in loop to iterate through an object "person".

Here we created an object called "person" with three properties we are going to use the for/in loop to display the property names as well as the values of those properties

var person = new Object();

person.name = "Tech Junkie";
person.occupation = "Blogger";
person.location = "Mars";

for(var p in person)
console.log(p + ": " + person[p]);

Here is the output:


2 comments:


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Javascript Training in Chennai . or learn thru Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry. JavaScript Training in Chennai

    ReplyDelete