How to use the JS keyword in the original address: http://sunct.iteye.com/blog/1709017
1.For ... In declares a loop/iterate operation for an array or an object's properties.
For An array , iterate over the array element , and for the object , iterate over the object's attributes;
JS Code
- var x
- var mycars = new Array ()
- Mycars[0] = "Saab"
- MYCARS[1] = "Volvo"
- MYCARS[2] = "BMW"
- for (x in mycars)
- {
- document.write (Mycars[x] + "<br/>")
- }
The output is:
Java code
- Saab
- Volvo
- BMW
Object Example: JS code
- var obj = {
- W: "Wen",
- J: "Jian",
- B: "Bao"
- }
- for (var v in obj) {
- document.write (v) +"<br/>";
- }
Output as: Java code
- W
- J
- B
2. Determine whether an object is an element/attribute of an array/object:Format: (variable in object) ... Attention
When an "object" is an array, "variable" refers to the "index" of the arrays;
When "Object" is an object, "variable" refers to the object's "Properties".
Examples of arrays:
JS Code
- var arr = ["A","B","2","3","str"];
- var result = ("b" in arr);
- var result1 = (4 in arr);
- document.write (result+"<br>");
- document.write (result1+"<br>");
Output as: Java code
- False
- True
Object Example: JS code
- var obj={
- W:"Wen",
- J:"Jian",
- B:"Bao"
- }
- var result= (2 in obj);
- var result1= ("J" in obj);
- document.write (Result) +"<br/>";
- document.write (RESULT1) +"<br/>";
Output as: Java code
- False
- True
How to use the "go" JS keyword in