js create array from for loop code example
Example 1: loop array javascript
var colors = ['red', 'green', 'blue'];
colors.forEach((color, colorIndex) => {
console.log(colorIndex + ". " + color);
});
Example 2: js create array from for loop
var yearStart = 2000;
var yearEnd = 2040;
var arr = [];
for (var i = yearStart; i < yearEnd+1; i++) {
arr.push(i);
}
Example 3: loop array in javascript
var colors = ["red", "green", "blue"];
for(var i = 0; i < colors.length; i++){
console.log(colors[i]);
}
Example 4: how to use for loops to work with array in javascript
for(let i = 0; i < myArray.length; i++){