遍历数组元素

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="utf-8">
 5         <title></title>
 6     </head>
 7     <body>
 8         <script>
 9             //将数组里面的元素挨个打印
10             var a1=['Q','s','c',1,4,9,'奥特曼','篮球'];
11             console.log(a1[0]);
12             console.log(a1[1]);
13             console.log(a1[2]);
14             
15             //使用for循环打印
16             for(var i=0;i<a1.length;i++){
17                 console.log(a1[i]);
18             }
19             //使用while打印
20             var i=0;
21             while(i<a1.length){
22                 console.log(a1[i]);
23                 i++
24             }
25         </script>
26     </body>
27 </html>
posted @ 2022-09-01 22:54  鬼牛阿飞  阅读(16)  评论(0编辑  收藏  举报