--------------
|index |value|
|0 |a |
|1 |b |
|2 |c |
|3 |d |
|4 |e |
|5 |f |
|6 |g |
|7 |h |
--------------
我需要在索引2和7之间进行循环。
答案 0 :(得分:1)
您可以按照以下代码使用for ... loop
:
var myArray = ["a", "b", "c", "d", "e", "f", "g", "h"];
// i = 2 for the starting index
//until you reach index 7
for (var i = 2; i <= 7; i++) {
console.log(myArray[i]);
//Do something
}
如果要将 7 替换为阵列中的最后一种情况,可以执行以下操作:
var myArray = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"];
// i = 2 for the starting index
//until you reach end of the array
for (var i = 2; i < myArray.length; i++) {
console.log(myArray[i]);
//Do something
}