looping over array in javascript code example
Example 1: javascript loop through array
const myArray = ['foo', 'bar'];
myArray.forEach(x => console.log(x));
for(let i = 0; i < myArray.length; i++) {
console.log(myArray[i]);
}
Example 2: javascript loop through array
var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
console.log(myStringArray[i]);
}
Example 3: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}