Answers for "javascript for each loop"

120

javascript foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
Posted by: Guest on April-27-2020
54

javascript foreach

var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});
Posted by: Guest on June-27-2019
31

js for each item do

let array = ['Item 1', 'Item 2', 'Item 3'];

array.forEach(item => {
	console.log(item); // Logs each 'Item #'
});
Posted by: Guest on February-20-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
18

javascript for each loop

var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
    console.log(color);
});
Posted by: Guest on July-19-2019
0

javascript for each loop

const a = ["a", "b", "c"];
for (const val of a) { // You can use `let` instead of `const` if you like
    console.log(val);
}
Posted by: Guest on August-31-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language