javascript .foreach

JavaScript
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']
const arraySparse = [1,3,,7]
let numCallbackRuns = 0

arraySparse.forEach((element) => {
  console.log(element)
  numCallbackRuns++
})

console.log("numCallbackRuns: ", numCallbackRuns)

// 1
// 3
// 7
// numCallbackRuns: 3
// comment: as you can see the missing value between 3 and 7 didn't invoke callback function.var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));  var fruits = ["apple", "orange", "cherry"];
fruits.forEach(myFunction);

  
function myFunction(item, index) {
  document.getElementById("demo").innerHTML 
  += index + ":" + item + "<br>"; 
} let listeDePays = ['France', 'Belgique', 'Japon', 'Maroc'];
listeDePays.forEach(pays => console.log(pays));
Source

Also in JavaScript: