Js循环做法

一、循环语句(参考:http://www.jb51.net/article/80844.htm)

1、for……in……

<script type="text/javascript">
var x
var mycars = new Array()
mycars[0] = "宝马"
mycars[1] = "奔驰"
mycars[2] = "宾利"
for (x in mycars){document.write(mycars[x])}
</script>

2、map

var x = [1,2,3,4].map( function(item) { 
    return item * 10; 
} );
// And now x is [10,20,30,40]

3、array

myStringArray = "abcdef";
for (var i = 0; i < myStringArray.length; i++) { 
 alert(myStringArray[i]); 
} 

  

  

posted on 2018-02-08 14:13  makeinchina  阅读(124)  评论(0编辑  收藏  举报

导航