Iterate with JavaScript While Loops code example
Example 1: Iterate with Do While Loops Javascript
var myArray = [];
var i = 10;
do {
myArray.push(i);
i++;
} while (i < 5)
console.log(i, myArray);
Example 2: Iterate with JavaScript While Loops
var ourArray = [];
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
var myArray = [];
var i = 5;
while (i >= 0) {
myArray.push(i);
i--;
}
Example 3: Iterate with JavaScript Do...While Loops
var ourArray = [];
var i = 5;
do {
ourArray.push(i);
i++;
} while (i < 5);