ÍøÂçѧԺ

w3pop.com :: ÍøÂçѧԺ :: JavaScript :: JS For...In

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

JavaScript
JSÊýѧ¶ÔÏó²Î¿¼
JS×Ö·û´®¶ÔÏó²Î¿¼
JSº¯Êý²Î¿¼
JSʼþ²Î¿¼
Javascript ³£ÓÃÕ..
FFºÍIEϵÄjs¼æÈÝ..
jQuery ¼òµ¥½éÉÜ
jQuery / ºËÐÄ / ..
jQuery / ºËÐÄ / ..
ÈçºÎʹÓÃJSÀ´ÅжÏ..
JavascriptÔÚIEºÍ..
3¸öjs×Ö·û±àÂ뺯Ê..
javascript ÖÐµÄ ..

JS For...In


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-28 ÐÞ¸Ä:2007-09-11 ä¯ÀÀ:15197 :: ::

The for...in statement is used to loop (iterate) through the elements of an array or through the properties of an object.
for...inÉùÃ÷ͨ¹ýÒ»×éÔªËØ»ò¶ÔÏóÊôÐÔ½øÐÐÑ­»·£¨Öظ´£©¡£


Examples
¾ÙÀý

For...In statement
How to use a for...in statement to loop through the elements of an array.
ÔõÑùͨ¹ýÒ»×éÔªËØÀ´Ê¹ÓÃfor...inÉùÃ÷½øÐÐÑ­»·¡£


JavaScript For...In Statement
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ÉùÃ÷ͨ¹ýÒ»×éÔªËØ»ò¶ÔÏóÊôÐÔ½øÐÐÑ­»·£¨Öظ´£©¡£

The code in the body of the for ... in loop is executed once for each element/property.
ÔÚfor...inÑ­»·Çû¸É²¿·ÖÀïµÄ´úÂëÕë¶Ôÿ¸öÔªËØ/ÊôÐÔÖ´ÐÐÒ»´Î¡£

Syntax
Óï·¨

for (variable in object)
{
code to be executed }

The variable argument can be a named variable, an array element, or a property of an object.
±äÁ¿¿ÉÒÔÊÇÊý×é»òÊǶÔÏóµÄÊôÐÔ¡£

Example
¾ÙÀý

Using for...in to loop through an array:
Êý×éʹÓÃfor...inÑ­»·£º

<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] + "<br />")
}

</script>
</body>
</html>

ÆÀÂÛ (15) 1 2 3 All