iteration in js code example

Example 1: how to iterate array in javascript

array = [ 1, 2, 3, 4, 5, 6 ]; 
   //set variable//set the stop count // increment each loop
for (let i = 0; i < array.length ;i++) { 
  
         array[i] //iterate through each index.
   //add the intructions you would like to perform.
    
             // add any method to array[
}

Example 2: javascript loop and array

var array = ["hello","world"];
array.forEach(item=>{
	console.log(item);
});

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: 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 ]