forEach

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

colors.forEach(function(color) {
  console.log(color);
});var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
    console.log(color);
});$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}users.forEach((user, index)=>{
	console.log(index); // Prints the index at which the loop is currently at
});let names = ['josh', 'joe', 'ben', 'dylan'];
// index and sourceArr are optional, sourceArr == ['josh', 'joe', 'ben', 'dylan']
names.forEach((name, index, sourceArr) => {
	console.log(color, idx, sourceArr)
});

// josh 0 ['josh', 'joe', 'ben', 'dylan']
// joe 1 ['josh', 'joe', 'ben', 'dylan']
// ben 2 ['josh', 'joe', 'ben', 'dylan']
// dylan 3 ['josh', 'joe', 'ben', 'dylan']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.
Source

Also in JavaScript: