javascript

For loop in Javascript

for (var i = 0; i < 5; i++) {
    console.log(i);
}

Nested for loop

for (var i = 0; i < 5; i++) {
    for (var j = 0; j < 2; j++) {
        console.log(i, j);
    }
}

Loop on array

var my_array = ["Apple", "banana", "Orange"];

for (var i = 0; i < my_array.length; i++) {
    console.log(my_array[i]);
}
Was this helpful?