Iterate Through an Array with a For Loop
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
Iterate Through an Array with a For Loop
var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
loop over an array
let fruits = ['Apple', 'Banana'];
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
// Apple 0
// Banana 1
iterate through an array
var arr = [1,2,3,4,5,6,7,8];
// Uses the usual "for" loop to iterate
for(var i= 0, l = arr.length; i< l; i++){
console.log(arr[i]);
}
console.log("========================");
//Uses forEach to iterate
arr.forEach(function(item,index){
console.log(item);
});
how to loop through an array
var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//loop thrugh all of the numbers of the array and print them
for(let i = 0; i < array.length; i++){
console.log(array[i]); //print all the array data in the length of i
}
//we can create some variable that store the array data and than display it
//using for...of
for(let data of array){
console.log(data); //print all the data that was stored in the "data" variable
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us