js loop methods code example
Example 1: loop array javascript
var colors = ['red', 'green', 'blue'];
colors.forEach((color, colorIndex) => {
console.log(colorIndex + ". " + color);
});
Example 2: javascript loop
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 3: javascript for loop 5 times
for (let step = 0; step < 5; step++) {
console.log('Walking east one step');
}
Example 4: javascript loop
var colors=["red","blue","green"];
for(let color of colors){
console.log(color)
}