When using forEach in JavaScript, the callback function is called with three parameters:
arr.forEach(function callback(currentValue, index, array) {
//your code here
})
In this scenario, both arr
and array
refer to the same array, with arr
being present within the closure of the callback function.
The question arises: what is the purpose of passing array
as a parameter to the callback function?