Javascript looping 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: for loop javascript
var i;
for (i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
Example 3: javascript loop
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 4: js for loops
let i;
for (i = 0; i < 6; ++i) {
console.log("Hello");
}
Example 5: java script loop
clear rectangle
Example 6: loop javascript
for (var i = 0; i < cats.length; i++) {
if (i === cats.length - 1) {
info += 'and ' + cats[i] + '.';
} else {
info += cats[i] + ', ';
}
}