iteration javascript code example

Example 1: for of js

let panier = ['fraise', 'banane', 'poire'];

for (const fruit of panier) {
  // console.log(fruit);
  console.log(panier.indexOf(fruit));
}

Example 2: iterate array in javascrpt

let array = [ 1, 2, 3, 4 ]; //Your array

for( let element of array ) {
	//Now element takes the value of each of the elements of the array
	//Do your stuff, for example...
  	console.log(element);
}

Example 3: 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 4: boucle for in js

let panier = ['fraise', 'banane', 'poire'];

for (const fruit in panier) {
    console.log(panier[fruit]);
}

Example 5: boucle for of javascript

let panier = ['fraise', 'banane', 'poire'];

for (const fruit of panier) {
  // console.log(fruit);
  console.log(panier.indexOf(fruit));
}

Example 6: javascript iterate array

String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray)
{
    // Do something
}