for each js
snippet in javascript

javascript foreach

user5799

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})

for each js

user1682

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

// Iterate over fruits below

// Normal way
fruits.forEach(function(fruit){
  console.log('I want to eat a ' + fruit)
});

javascript foreach

user5157

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

colors.forEach(function(color) {
  console.log(color);
});

javascript foreach example

user6498

var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
    console.log(color);
});

foreach javascript

user2445

let words = ['one', 'two', 'three', 'four'];
words.forEach((word) => {
  console.log(word);
});
// one
// two
// three
// four

foreach javascript

user3377

var items = ["item1", "item2", "item3"]
var copie = [];

items.forEach(function(item){
  copie.push(item);
});