for i in range javascript code example
Example 1: js loop
var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: javascript loop
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item);
});
Example 3: javascript loop through array
var colors = ["red","blue","green"];
colors.forEach(function(color) {
console.log(color);
});
Example 4: range javascript
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
Example 5: loop an array in javascript
let array = ["loop", "this", "array"];
for (let i = 0; i < array.length; i++) {
console.log(array[i]);
}
Example 6: javascript loop through array
const array1 = ['a', 'b', 'c'];
array1.forEach(element => console.log(element));