Answers for "javascript array loop with index"

2

js iterate array index

for (let [index, val] of array.entries()) {
        // your code goes here    
}
Posted by: Guest on May-16-2021
8

loop array javascript

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

for each js

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below

// Normal way
fruits.forEach(function(fruit){
  console.log('I want to eat a ' + fruit)
});
Posted by: Guest on March-29-2020

Code answers related to "javascript array loop with index"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language