Answers for "javascript for loop singular array"

8

loop array javascript

var colors = ['red', 'green', 'blue'];
	
	colors.forEach((color, colorIndex) => {
     console.log(colorIndex + ". " + color); 
    });
Posted by: Guest on April-08-2020
1

javascript loop through array

let my_array = [1, 2, 3, 4, 5];

// standard for loop
for(let i = 0; i < my_array.length; i++) {
  console.log(my_array[i])  // 1 2 3 4 5 6
}

// for and of method
for(let i of my_array) {
	console.log(i)
}

/*
Results:
1 2 3 4 5
1 2 3 4 5
(From both methods)
*/
Posted by: Guest on December-31-2020

Code answers related to "javascript for loop singular array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language