for in javascript example

Example 1: javascript for loop

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

Example 2: loop javascript

// infinite for loop
for(let i = 1; i > 0; i++) {
    // block of code
}

Example 3: for in loop javascript

let array = [1,2,3,4,5,6,7,8,9,10]; 
// our array that we will use the for loop on
for (let i = 0; i < array.length; i++) { 
  // this loop will console log the element at array[i] starting at 0
  // and will continue looping for i < array.length 
  console.log(array[i]);
  // after each loop i will increase by 1
}

// this will console log
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10

Example 4: for in loop javascript

var person = {"name":"taylor","age":31};
for (property in person) {
	console.log(property,person[property]);
}
//name taylor
//age 31

Example 5: for javascipt

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

Example 6: javascript for of

const numbers = [1,2,3,4];

for(const item of numbers){
  console.log(item);
}

Tags:

Java Example