loop function js 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: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
Example 3: for loop javascript
var i;
for (i = 0; i < 10 ; i++) {
}
Example 4: for next loop javasxcrop
for (i = 0; i < 5; i++) {}
Example 5: loop javascript
for (var i = 0; i < cats.length; i++) {
if (i === cats.length - 1) {
info += 'and ' + cats[i] + '.';
} else {
info += cats[i] + ', ';
}
}
Example 6: javascript loop
var items=["a","b","c"];
for(let item of items){
console.log(item)
}