标签:
1:数值累加的方式循环
for (var i = 0; i <= 10; i++) {
document.write("The number is " + i);
document.write("<br />");
}
2:枚举数组或对象中值来循环,类似其他语言的for each,遇到数组时key为数据下标,遇到对象时key为对象(名称:值)项的名称。
var mycars = new Array();
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";
for (var x in mycars) {
document.write(mycars[x] + "<br />");
}
标签:
原文地址:http://www.cnblogs.com/xiaozhuzhuandxiaomoney/p/5519704.html