Answers for "how to use loop in javascript"

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
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
1

javascript loop

//There are many loops in javascript that get the job done
let colors = ["red","blue","green"];

//More detail about loop => shorturl.at/avIRW
for(let i in colors){
  console.log(colors[i])
}
//More detail about loop => shorturl.at/hBUW2
colors.forEach(color => {
  console.log(color)
})
//More detail about loop => shorturl.at/pLOV6
colors.map(color => {
  console.log(color)
})
//More detail about loop => shorturl.at/hlstV
for(let i = 0; i < colors.length; i++){
  console.log(colors[i])
}
//More detail about loop => shorturl.at/iKS38
let i = 0;
while ( i < colors.length ){
  console.log(colors[i])
  i++
}
Posted by: Guest on September-01-2021
5

javascript loop

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

loops javascript

/*Loops are great tools when you need your program to run a code block a 
certain number of times or until a condition is met, but they need a 
terminal condition that ends the looping. Infinite loops are likely to 
freeze or crash the browser, and cause general program execution mayhem, 
which no one wants.

Infinite loop example(do not call this function!):*/
function loopy() {
  while(true) {
    console.log("Hello, world!");
  }
}

/*Loop example with terminal condition:*/
function myFunc() {
  for (let i = 1; i <= 4; i += 2) {
    console.log("Still going!");
  }
}
Posted by: Guest on February-03-2021
-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 "how to use loop in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language