Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Iterate with JavaScript While Loops

var ourArray = [];
var i = 0;
while(i < 5) {
  ourArray.push(i);
  i++;
} // 0 to 4 [ 0, 1, 2, 3, 4 ]

var myArray = [];
var i = 5;
while (i  >= 0) {
  myArray.push(i);
  i--;
} // 5 to 0 (reverse) [ 5, 4, 3, 2, 1, 0 ]
Comment

Iterate with Do While Loops Javascript

var myArray = [];

var i = 10;

 do {  // The do while loop will always run atleast once before checking the condtion. This will return false and break out of the loop.
	myArray.push(i);
    i++;
} while (i < 5)

console.log(i, myArray);
Comment

loop do while javascript

let arr = ['jan', 'feb', 'mar', 'apr', 'may'], i = 0;
// do something at least 1 time even if the condition is false
do{
	console.log(arr[i]);
	i++;
}while(arr.includes('dec'));
// output: jan 
Comment

Iterate with JavaScript Do...While Loops

var ourArray = []; 
var i = 5;
do {
  ourArray.push(i);
  i++;
} while (i < 5); // it will work once and stop looping.
Comment

iterate with javascript while loops

var myArray = []



var i = 0;
while(i < 5){
    myArray.push(i)
    i++
}


console.log(myArray);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to make an event listener only work once 
Javascript :: trigger a button click with javascript on the enter key in a text box 
Javascript :: prevent form submit html javascript jquery 
Javascript :: Export multiple variable javascript 
Javascript :: js redux example 
Javascript :: brython.js download 
Javascript :: GET method firebase realtime database react 
Javascript :: document.queryselector 
Javascript :: mongodb find and update one field 
Javascript :: javascript check if length is greater than 0 
Javascript :: how to skip the execution or for loop using continue js 
Javascript :: javascript iterate through an object 
Javascript :: upload file react onclick 
Javascript :: javascript debugger online 
Javascript :: react typescript set type 
Javascript :: switch for comparing greater value 
Javascript :: how to deploy firebase angular 10 
Javascript :: current date jquery and current day 
Javascript :: react barcode scanner 
Javascript :: age validation jquery 
Javascript :: node settimeout 
Javascript :: react: create form change state on input 
Javascript :: stop python script nodejs 
Javascript :: create cookie javascript react 
Javascript :: copia array javascript 
Javascript :: scroll up link 
Javascript :: how to use fetch in gatsby 
Javascript :: how to use mui 
Javascript :: js get path from url 
Javascript :: react input radio button 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =