javascript中的for……in循环

时间:2024-08-27 20:35:08

<script type="text/javascript">
   var theBeatles=new Array("John","Paul","Gearge","Ringo");
   for(var loopCounter=0;loopCounter<theBeatles.length;loopCounter++){
       document.write(theBeatles[loopCounter]+"<br>");
   }
   var indexKey;
   for(indexKey in theBeatles){
       document.write("indexKey is "+indexKey+"<br>");
       document.write("item value is "+theBeatles[indexKey]+"<br><br>");
   }
   </script>