JavaScript Tutorial/Statement/For In

Материал из Web эксперт
Версия от 08:25, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

for...in

The for...in loop accesses to all the enumerated properties of a JavaScript object.

The statement(s) in the loop are executed for each property of an object until every property has been accessed.

Any parts of an object that are not enumerated are not accessed by this looping structure.

The format of the for...in loop looks like the following:



for (variable in object) {
      statement;
    }


Window Object Properties Array

<HTML>
<HEAD>
   <TITLE>Window Object Properties Array</TITLE>
</HEAD>
<BODY>
<SCRIPT>
for (var i in window) {
  document.write ("Window property(" + i +  "): " +
     window[i] + "<BR>");
}
</SCRIPT>
</BODY>
</HTML>