array in loop javascript code example
Example 1: loop array javascript
var colors = ['red', 'green', 'blue'];
colors.forEach((color, colorIndex) => {
console.log(colorIndex + ". " + color);
});
Example 2: 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 3: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}