how to write a for loop in javascript code example

Example 1: javascript for loop

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

Example 2: for loop javascript

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

Example 3: java script loop

clear rectangle

Example 4: loop javascript

//this is javascript
var speed = 100;
setInterval(function() {
//DO SOMETHING THAT REPEATS
},speed);

Example 5: javascript loop

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

Example 6: for in js loop

Example:
const object = { a: 1, b: 2, c: 3 };

for (const property in object) {
  console.log(`${property}: ${object[property]}`);
}

// expected output:
// "a: 1"
// "b: 2"
// "c: 3"


Syntax:
for (variable in object)
  statement