var colors = ['red', 'blue', 'green']; colors.forEach(function(color) { console.log(color); });
const avengers = ['thor', 'captain america', 'hulk']; avengers.forEach((item, index)=>{ console.log(index, item) })
let words = ['one', 'two', 'three', 'four']; words.forEach((word) => { console.log(word); }); // one // two // three // four
var colors = ["red", "blue", "green"]; colors.forEach(function(color) { console.log(color); });
let numbers = ['one', 'two', 'three', 'four']; numbers.forEach((num) => { console.log(num); }); // one //two //three // four
const numList = [1, 2, 3]; numList.forEach((number) => { console.log(number); });
var items = ["item1", "item2", "item3"] var copie = []; items.forEach(function(item){ copie.push(item); });
var stringArray = ["first", "second"]; myArray.forEach((string, index) => { var msg = "The string: " + string + " is in index of " + index; console.log(msg); // Output: // The string: first is in index of 0 // The string: second is in index of 1 });
const arr = [10,20,30,40] arr.forEach(function(item, index){ console.log(item, index); })
let colors = ['red', 'blue', 'green']; // idx and sourceArr optional; sourceArr == colors colors.forEach(function(color, idx, sourceArr) { console.log(color, idx, sourceArr) }); // Output: // red 0 ['red', 'blue', 'green'] // blue 1 ['red', 'blue', 'green'] // green 2 ['red', 'blue', 'green']