Answers for "create array javascript for loop"

8

loop array javascript

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

for loop on a array

var array = [1, 2, 3, 4, 5];
// made an array

for (var i = 0; array[i]; i++) // browse your array with this simple condition on index
	console.log('element '+i+' = '+array[i]);

//output:
element 0 = 1
element 1 = 2
element 2 = 3
element 3 = 4
element 4 = 5
Posted by: Guest on August-04-2021
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
}
Posted by: Guest on May-18-2020
1

iterate array in javascrpt

let array = [ 1, 2, 3, 4 ]; //Your array

for( let element of array ) {
	//Now element takes the value of each of the elements of the array
	//Do your stuff, for example...
  	console.log(element);
}
Posted by: Guest on May-14-2020
-1

javascript loop array

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
    
    for( var i = 0; i < arr.length; i--){ 
    
        if ( arr[i] === 5) { 
    
            arr.splice(i, 1); 
        }
    
    }
    
    //=> [1, 2, 3, 4, 6, 7, 8, 9, 0]
Posted by: Guest on April-27-2021

Code answers related to "create array javascript for loop"

Code answers related to "Javascript"

Browse Popular Code Answers by Language