all loops in javascript code example
Example 1: javascript for loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: javascript loop through array
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));
Example 3: forloop in js
for(i = 0; i < x; ++i){
}
Example 4: how to make a javascript for loop
var tops = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144];
for (let i = 0; i < tops.length; i++) {
document.write(tops[i] + "tops");
}
Example 5: javascript for loop[
for(i=0;i<=5;i++){
console.log(i);}