So I'm trying to understand functional programming and higher order functions in specific. What I never clearly understood, was how callback function's parameters have a connection to, for example, an array?
To be more clear, let's take this code example:
var friends = ["Mike", "Stacy", "Andy", "Rick"];
friends.forEach(function (eachName, index){
console.log(index + 1 + ". " + eachName); // 1. Mike, 2. Stacy, 3. Andy, 4. Rick
});
How a callback parameter eachName
knows that it means to return the item from array and index
is supposed to return an index of array? How the connection between an array and callback parameter works?