jerkzhang,stay hungry, stay foolish
来源《JS For循环》:
JavaScript循环语句可以让程序重复运行代码块中的语句。
JS For 循环1:
for ( 语句1; 语句2; 语句3; ) { 代码块 }
语法解析:
JS For 循环示例:
var i, text; var gangs = ["太平天国", "义和团", "天地会", "日月神教", "红花会", "学生会"]; for (i = 0; i < gangs.length; i++) { text += gangs[i] + "<br>"; }
JS For 循环示例解析:
JS For 循环2:
for / in 语句的语法
for ( i in obj ) { 代码块 }
语法解析:
JS For 循环示例1:
var gangs = ["太平天国", "义和团", "天地会", "日月神教", "红花会", "学生会"]; var text = ""; var i; for (i in gangs) { text += i + " ---> " + gangs[i] + "<br>"; }
JS For 循环示例2:
var gangs = { "taiping": "太平天国", "yihe": "义和团", "tiandi": "天地会", "riyue": "日月神教", "honghua": "红花会", "xuesheng": "学生会" }; var text = ""; var i; for (i in gangs) { text += i + " ---> " + gangs[i] + "<br>"; }