javascript array in loop 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
let array = ['Item 1', 'Item 2', 'Item 3'];
for (let item of array) {
console.log(item);
}
Example 3: how to use for loops to work with array in javascript
let myArray = ["one", "two", "three", "four"];