for of for in js code example

Example 1: for of js

let list = [4, 5, 6];

for (let i in list) {
   console.log(i); // "0", "1", "2",
}

for (let i of list) {
   console.log(i); // "4", "5", "6"
}

Example 2: 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 3: javascript for of loop

for (variable of iterable) {
  statement
}

Example 4: how to use for of in javascript

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

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

Example 5: use these instead of a for loop javascript

const array = [1,2,3,4,5];const evenNumbers = array.filter(function(elem) {   // expressions that return 'true' are retained   return elem % 2 == 0;});

Example 6: es6 for-of loop

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

Tags:

Php Example