for...in statement

Source: Internet
Author: User
Statement

Executes one or more statements that correspond to each element of an object, or an array.

for (variable in [object | array])
   statements

Parameters

Variable

Required option. A variable that can be either a property of object or any element of an array .

Object, array

Options available. The object or array to traverse on.

Statement

Options available. One or more statements to be executed relative to each attribute of object or to each element of the array . Can be a compound statement .

Description

Before each iteration of the loop,variable is assigned the next attribute of object or the next element of the array . It can then be used in any statement within the loop, as if it is using the property of object or the element of the array .

When iterating over an object, there is no way to determine or control the order in which the members of the object are assigned to the variable . The iteration is executed within the array in the order of the elements, that is, 0, 1, 2 、......

Example

The following example illustrates the use of the for ... in statement, which uses an object as a federated array:

Create certain variables.   var a, key, s = "";  initializes the object.   The a = {"a" : "Athens" , "b" : "Belgrade", "c" : "Cairo"}  iteration property. for (in a)   {s += a[key] + "&ltBR>";   }   return(s);}

Requirements

Version 5

Note Use the enumerator object to iterate through the members of the collection.

Please see

For Statement | While statement



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.