“JavaScript dla tablicy pętli” Kod odpowiedzi

Tablica pętli JavaScript

function delay(time) {
  return new Promise(resolve => setTimeout(resolve, time));
}

delay(1000).then(() => console.log('ran after 1 second1 passed'));
Powerful Puma

Kod JavaScript, aby zapętlić się przez tablicę

var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}
Grepper

Pętla JavaScript

var colors = ['red', 'green', 'blue'];
	
	colors.forEach((color, colorIndex) => {
     console.log(colorIndex + ". " + color); 
    });
Magnificent Moth

Pętla tablica JS

var arr = ["f", "o", "o", "b", "a", "r"]; 
for(var i in arr){
	console.log(arr[i]);
}
FlashingMustard

pętla JavaScript przez tablicę

var colors = ["red","blue","green"];
colors.forEach(function(color) {
  console.log(color);
});
Gifted Gerenuk

JavaScript dla tablicy pętli

//pass an array of numbers into a function and log each number to the console
function yourFunctionsName(arrayToLoop){
  
  //Initialize 'i' as your counter set to 0
  //Keep looping while your counter 'i' is less than your arrays length 
  //After each loop the counter 'i' is to increased by 1
  for(let i = 0; i <arrayToLoop.length; i++){
    	
    	//during each loop we will console.log the current array's element
    	//we use 'i' to designate the current element's index in the array
    	console.log(arrayToLoop[i]) 
    }
}

//Function call below to pass in example array of numbers
yourFunctionsName([1, 2, 3, 4, 5, 6]) 
Michael Futral

Odpowiedzi podobne do “JavaScript dla tablicy pętli”

Pytania podobne do “JavaScript dla tablicy pętli”

Więcej pokrewnych odpowiedzi na “JavaScript dla tablicy pętli” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu