JavaScript for / in statement
JavaScript Statements Reference Manual
Examples
Cyclic object properties:
var person = {fname: "John", lname: "Doe", age: 25};
var text = "";
var x;
for (x in person) {
text + = person [x];
}
var text = "";
var x;
for (x in person) {
text + = person [x];
}
text output is:
John Doe 25
try it"
Definition and Usage
for / in statement to loop object properties.
Loop code Each time, the properties will be an array element or an object once the operation.
JavaScript support different types of loops:
- for - a certain number of cycles code block
- for / in - loop through the properties of an object
- the while - when a specified condition is true cycle specified block of code
- do / the while - the same as the specified condition is true cycle specified block of code
Note: Do not use for / in statement to loop index of the array, you can use a for statement instead.
Browser Support
Statements | |||||
---|---|---|---|---|---|
for / in | Yes | Yes | Yes | Yes | Yes |
grammar
for(var in object) {
Code block execution
}
Code block execution
}
Parameter Value
parameter | description |
---|---|
var | have to. Specified variable can be an array element, it can be a property of the object. |
object | have to. Specified object iteration. |
technical details
JavaScript version: | 1.0 |
---|
Related Pages
JavaScript Tutorials: JavaScript the For loop
JavaScript Reference Manual: JavaScript for statements
JavaScript Statements Reference Manual