Answers for "loop through array data js"

48

javascript code to loop through array

var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
    console.log(colors[i]);
}
Posted by: Guest on July-22-2019
0

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
}
Posted by: Guest on May-24-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language