码迷,mamicode.com
首页 > 其他好文 > 详细

for循环的使用

时间:2019-11-16 21:27:17      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:bar   for   img   too   数组   class   for循环   bsp   length   

用for循环取数组的值

第一种

技术图片
    <script>
        // 用for循环取数组的值
        function f1(){
            let a = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘];
            for (let item in a){
                // console.log(a[item]);
                let s = a[item] + "<br/>";
                document.write(s);
        }
        }
        setInterval(‘f1();‘, 500);
    <script/>
技术图片

第二种

技术图片
<script>
        function f1(){
            let a = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘];
            for (let item=0; item<a.length; item++){
                // console.log(a[item]);
                let s = a[item] + "<br/>";
                document.write(s);
        }
        }
        setInterval(‘f1();‘, 500);
</script>
技术图片

 

 

用for循环取对象的值

技术图片
    <script>
        //用for循环取对象的值
        function f1(){
            let a = {‘k1‘:‘A‘, ‘k2‘:‘B‘, ‘k3‘:‘C‘, ‘k4‘:‘D‘,‘k5‘:‘E‘};
            for (let item in a){
                // console.log(a[item]);
                let s = a[item] + "<br/>";
                document.write(s);
        }
        }
        setInterval(‘f1();‘, 500)
    </script>

for循环的使用

标签:bar   for   img   too   数组   class   for循环   bsp   length   

原文地址:https://www.cnblogs.com/wjybk/p/11873438.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!