Answers for "for loop js example"

220

javascript for loop

var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) { 
  console.log(colors[i]);
}
Posted by: Guest on June-17-2019
14

js for loop

var i; //defines i
for (i = 0; i < 5; i++) { //starts loop
  console.log("The Number Is: " + i); //What ever you want
}; //ends loop
//Or:
console.log("The Number Is: " + 0);
console.log("The Number Is: " + 1);
console.log("The Number Is: " + 2);
console.log("The Number Is: " + 3);
console.log("The Number Is: " + 4);
//They do the same thing!
//Hope I helped!
Posted by: Guest on June-21-2020
12

javascript loop

let array = ['Item 1', 'Item 2', 'Item 3'];

for (let index = 0; index < array.length; index++) {
  console.log("index", index);
  console.log("array item", array[index]);
}
Posted by: Guest on March-04-2020
5

javascript loop

var colors=["red","blue","green"];
for(let color of colors){
  console.log(color)
}
Posted by: Guest on December-06-2019
4

javascript loop

let array = ["foo", "bar"]

let low = 0; // the index to start at
let high = array.length; // can also be a number

/* high can be a direct access too
	the first part will be executed when the loop starts 
    	for the first time
	the second part ("i < high") is the condition 
    	for it to loop over again.
    the third part will be executen every time the code 
        block in the loop is closed.
*/ 
for(let i = low; i < high; i++) { 
  // the variable i is the index, which is
  // the amount of times the loop has looped already
  console.log(i);
  console.log(array[i]); 
} // i will be incremented when this is hit.

// output: 
/*
	0
    foo
    1
    bar
*/
Posted by: Guest on December-16-2020
-1

javascript loop

{"coord":{"lon":69.4167,"lat":34.5},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":294.37,"feels_like":293.07,"temp_min":294.37,"temp_max":294.37,"pressure":1008,"humidity":20,"sea_level":1008,"grnd_level":811},"visibility":10000,"wind":{"speed":1.72,"deg":278,"gust":1.88},"clouds":{"all":0},"dt":1624587596,"sys":{"type":1,"id":7381,"country":"AF","sunrise":1624579865,"sunset":1624631919},"timezone":16200,"id":1138957,"name":"Kabul","cod":200}
Posted by: Guest on June-25-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language