w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS For...In
The for...in statement is used to loop (iterate) through the elements of an array or through the properties of an object.
for...inÉùÃ÷ͨ¹ýÒ»×éÔªËØ»ò¶ÔÏóÊôÐÔ½øÐÐÑ»·£¨Öظ´£©¡£
For...In statement
How to use a for...in statement to loop through the elements of an array.
ÔõÑùͨ¹ýÒ»×éÔªËØÀ´Ê¹ÓÃfor...inÉùÃ÷½øÐÐÑ»·¡£
The for...in statement is used to loop (iterate) through the elements of an array or through the properties of an object.
for...inÉùÃ÷ͨ¹ýÒ»×éÔªËØ»ò¶ÔÏóÊôÐÔ½øÐÐÑ»·£¨Öظ´£©¡£
The code in the body of the for ... in loop is executed once for each element/property.
ÔÚfor...inÑ»·Çû¸É²¿·ÖÀïµÄ´úÂëÕë¶Ôÿ¸öÔªËØ/ÊôÐÔÖ´ÐÐÒ»´Î¡£
Syntax
Óï·¨
for (variable in object) |
The variable argument can be a named variable, an array element, or a property of an object.
±äÁ¿¿ÉÒÔÊÇÊý×é»òÊǶÔÏóµÄÊôÐÔ¡£
Using for...in to loop through an array:
Êý×éʹÓÃfor...inÑ»·£º
<html> <script type="text/javascript"> </body> |