How to use the "go" JS keyword in

Source: Internet
Author: User

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
    1. var x
    2. var mycars = new Array ()
    3. Mycars[0] = "Saab"
    4. MYCARS[1] = "Volvo"
    5. MYCARS[2] = "BMW"
    6. for (x in mycars)
    7. {
    8. document.write (Mycars[x] + "<br/>")
    9. }

The output is:

Java code
    1. Saab
    2. Volvo
    3. BMW
Object Example: JS code
    1. var obj = {
    2. W: "Wen",
    3. J: "Jian",
    4. B: "Bao"
    5. }
    6. for (var v in obj) {
    7. document.write (v) +"<br/>";
    8. }
Output as: Java code
    1. W
    2. J
    3. 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
    1. var arr = ["A","B","2","3","str"];
    2. var result = ("b" in arr);
    3. var result1 = (4 in arr);
    4. document.write (result+"<br>");
    5. document.write (result1+"<br>");
Output as: Java code
    1. False
    2. True
Object Example: JS code
  1. var obj={
  2. W:"Wen",
  3. J:"Jian",
  4. B:"Bao"
  5. }
  6. var result= (2 in obj);
  7. var result1= ("J" in obj);
  8. document.write (Result) +"<br/>";
  9. document.write (RESULT1) +"<br/>";
Output as: Java code
    1. False
    2. True

How to use the "go" JS keyword in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.