JavaScriptFor... In usage _ basic knowledge

Source: Internet
Author: User
JavaScriptFor... In usage method For... In declaration is used to traverse the attributes of an array or object (cyclic operation is performed on attributes of an array or object ).
JavaScript For... In Declaration
For... In declarations are used to perform cyclic operations on the attributes of arrays or objects.
Each time the code in the for... in loop is executed, an operation is performed on the elements or attributes of the array.
Syntax:
For (variable in object)
{
Run the code here
} Variable is used to specify a variable. the specified variable can be an array element or an object attribute.
Instance:
Use for... in to traverse the array cyclically.

<Html> <body> <script type = "text/javascript"> var x var mycars = new Array () mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW" for (x in mycars) {document. write (mycars [x] + "")} script </body> </ptml>
[Ctrl + A Select All Note: If you need to introduce external Js, you need to refresh it to execute]

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.