--------------
|index |value|
|0 |a |
|1 |b |
|2 |c |
|3 |d |
|4 |e |
|5 |f |
|6 |g |
|7 |h |
--------------
I need to loop in between index 2 and 7. How could I achieve it?
--------------
|index |value|
|0 |a |
|1 |b |
|2 |c |
|3 |d |
|4 |e |
|5 |f |
|6 |g |
|7 |h |
--------------
I need to loop in between index 2 and 7. How could I achieve it?
You can use a for ... loop
as in the code below:
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
}
If you want to replace the 7 by the last case in your array you can do:
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
}