for of javascript example

Example 1: javascript for of

const array = ['hello', 'world', 'of', 'Corona'];

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

Example 2: for in loop javascript

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

Example 3: for of loop javascript

const array1 = ['a', 'b', 'c'];

for (const element of array1) {
  console.log(element);
}

// expected output: "a"
// expected output: "b"
// expected output: "c"

Example 4: for of loop syntax javascript

for (let step = 0; step < 5; step++) {
  // Runs 5 times, with values of step 0 through 4.
  console.log('Walking east one step');
}

Example 5: javascript for of

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

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

Example 6: Iterate with JavaScript For Loops

var myArray = [];
for (var i = 1; i <= 5; i++){
    myArray.push(i);
} 
console.log(myArray) // console output [ 1, 2, 3, 4, 5 ]

Tags:

Php Example