用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>
原文:https://www.cnblogs.com/wjybk/p/11873438.html