js loop
snippet in javascript

javascript loop through array

user6448

var data = [1, 2, 3, 4, 5, 6];

//traditional for loop
for(let i=0; i<=data.length; i++) {
  console.log(data[i])  // 1 2 3 4 5 6
}

//using for/of
for(let i of data) {
	console.log(i) // 1 2 3 4 5 6
}

//using forEach
data.forEach((i) => {
  console.log(i) // 1 2 3 4 5 6
})
//BUT ->  forEach method is about 95% slower than the traditional for loop

//using map
data.map((i) => {
  console.log(i) // 1 2 3 4 5 6
})

javascript for loop

user3964

for (var i; i < 10; i++) {
  
}

js for loop

user9110

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!

javascript for

user264

let str = "";

for (let i = 0; i < 9; i++) {
  str = str + i;
}

console.log(str);
// expected output: "012345678"

js loop

user7695

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

for loop javascript

user4887

var i;
for (i = 0; i < cars.length; i++) {
  text += cars[i] + "<br>";
}