Javascript for in loop

It is used to get the iteration value from the object.

Syntax:-


for (variable in iterable) {
  // logic 
}

Example:- get the user object key’s value.


var user ={name:"John",age:35,sex:"Male"}
for(var element in user){
	
 console.log(user[element]);
}
Output:- John 35 Male

Try it Yourself

Get the object’s keys


var user ={name:"John",age:35,sex:"Male"}
for(var element in user){
	
	console.log(element);
}
Output:- name age sex