js for loop of code example

Example 1: javascript for of

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

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

Example 2: for i

# For loops in Dip

for i = 0 to 5 then print(i)

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: es6 for-of loop

for (let itme of list) {
  ...
}

Tags:

Cpp Example