define:
for/in statement is used to loop through the object properties。
Grammar:
for (var in object) {
code
}
parameter values:
parameter | describe |
---|---|
var | Must.variable can be an array element or an attribute of an object. (指定的变量可以是数组元素,也可以是对象的属性。) |
object | Must.Object that specifies the iteration. (指定迭代的的对象。) |
Example:
HTML:
1 <p id="demo"></p>
Javascript:
1 function myFunction() { 2 var string = {lesson:"web", verb:"is", describe:"fun"}; 3 4 var text = ""; 5 var x; 6 for (x in string) { 7 8 text += string[x] + " "; 9 } 10 document.getElementById("demo").innerHTML = text; 11 }
The code 's output:
web is fun
Related Pages:
JavaScript for/in : http://www.runoob.com/jsref/jsref-forin.html
Javascript statement : http://www.runoob.com/jsref/jsref-statements.html