for loop with array javascript code example
Example 1: javascript code to loop through array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
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: iterate array in javascrpt
let array = [ 1, 2, 3, 4 ];
for( let element of array ) {
console.log(element);
}
Example 4: javascript for loop[
for(i=0;i<=5;i++){
console.log(i);}