how to iterate over an array code example
Example 1: javascript loop through array
var data = [1, 2, 3, 4, 5, 6];
for(let i=0; i<=data.length; i++) {
console.log(data[i])
}
for(let i of data) {
console.log(i)
}
for(let i in data) {
console.log(i)
console.log(data[i])
}
data.forEach((i) => {
console.log(i)
})
data.map((i) => {
console.log(i)
})
Example 2: iterate through array javascript
const array = ["one", "two", "three"]
array.forEach(function (item, index) {
console.log(item, index);
});
Example 3: javascript loop through array
var colors = ["red","blue","green"];
colors.forEach(function(color) {
console.log(color);
});
Example 4: how to loop through an array
int[] numbers = {1,2,3,4,5};
for (int i = 0; i < numbers.length; i++) {
System.out.println(i);
}
Example 5: javascript loop through array
JavaScript Loop Through Array