for loop for arreys javascript code example

Example 1: javascript loop

let array = ['Item 1', 'Item 2', 'Item 3'];

for (let index = 0; index < array.length; index++) {
  console.log("index", index);
  console.log("array item", array[index]);
}

Example 2: javascript loop through array

let array = ['Item 1', 'Item 2', 'Item 3'];

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

Example 3: javascript iterate through for loop

var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);
    //Do something
}