for loop through a list javascript code example
Example 1: javascript loop through array
var colors = ["red","blue","green"];
colors.forEach(function(color) {
console.log(color);
});
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]);
//Do something
}
Example 3: how to loop through array of numbers in javascript
let numbers = [1,2,3,4,5];
let numbersLength = numbers.length;
for ( let i = 0; i < numbersLength; i++) {
console.log (numbers[i]);
}
Example 4: javascript loop
var colors=["red","blue","green"];
for(let color of colors){
console.log(color)
}