how to loop through an array in js code example
Example 1: loop an array in javascript
let array = ["loop", "this", "array"]; // input array variable
for (let i = 0; i < array.length; i++) { // iteration over input
console.log(array[i]); // logs the elements from the current input
}
Example 2: 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 3: iterate through array js
let arbitraryArr = [1, 2, 3];
// below I choose let, but var and const can also be used
for (let arbitraryElementName of arbitraryArr) {
console.log(arbitraryElementName);
}