geo*_*ock 27
对于循环
for (i = startValue; i <= endValue; i++) {
// Before the loop: i is set to startValue
// After each iteration of the loop: i++ is executed
// The loop continues as long as i <= endValue is true
}
Run Code Online (Sandbox Code Playgroud)
对于......循环
for (i in things) {
// If things is an array, i will usually contain the array keys *not advised*
// If things is an object, i will contain the member names
// Either way, access values using: things[i]
}
Run Code Online (Sandbox Code Playgroud)
使用for...in循环来迭代数组是不好的做法.它违反了ECMA 262标准,并且当非标准属性或方法添加到Array对象时会导致问题,例如Prototype.
(感谢Chase Seibert在评论中指出这一点)
循环
while (myCondition) {
// The loop will continue until myCondition is false
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10801 次 |
| 最近记录: |