js loop array code example

Example 1: 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!

Example 2: js loop array

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

Example 3: loop array javascript

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

Example 4: js loop array

let colors = ['red', 'green', 'blue'];
for (const color of colors){
    console.log(color);
}

Example 5: js loop array

// Event snippet for Purchase (Google Ads - 7 day click, 1 day view) conversion page

Example 6: JS Loop Array

//create an array like so:
var colors = ["red","blue","green"];

//you can loop through an array like this:
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}

Tags:

Java Example