5.Javascript语法-循环语句for循环

时间:2022-08-22 17:33:31

JavaScript循环语句

  1. for循环、for/in
  2. while循环、do…while

for循环

<script> var i=[1,2,3,4,5,6]; for(var j= 0;j<6;j++){ document.write(i[j]+"、"); } </script>

也可以把var j=0和j++拿出来

<script> var i=[1,2,3,4,5,6]; var j= 0; for(;j<6;){ document.write(i[j]+"、"); j++; } </script>

for/in

<script> var i=[1,2,3,4,5,6]; var j; for(j in i){ document.write(i[j]+"<br/>"); } </script>