loop over a number of elements in array javascript but not all elemnts code example

Example 1: javascript loop through array

const myArray = ['foo', 'bar'];

myArray.forEach(x => console.log(x));

//or

for(let i = 0; i < myArray.length; i++) {
  console.log(myArray[i]);
}

Example 2: js loop through array

// ES6 for-of statement
for (const color of colors){
    console.log(color);
}

// Array.prototype.forEach
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
  console.log(item, index);
});

// Sequential for loop
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);
    //Do something
}