Answers for "traversing array in javascript"

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

traverse an array in javascript

//Method 1 using for loop

let array = [ 1, 2, 3, 4, 5, 6 ]; 
for (let index = 0; index < array.length; index++) { 
    console.log(array[index]); 
}

//Method 2 using for Of loop

for (let traverse of array ){
  console.log(traverse)
}
Posted by: Guest on February-20-2021
0

javascript loop and array

var array = ["hello","world"];
array.forEach(item=>{
	console.log(item);
});
Posted by: Guest on June-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language