The forEach()
method calls a function once for each element in an
array, in order.
Note: the function is not executed for array elements without values.
array.forEach(function(currentValue, index, arr), thisValue)
Parameters: This method accepts five parameters as mentioned above and described below:
Return value: The return value of this method is always undefined. This method may or may not change the original array provided as it depends upon the functionality of the argument function.
var sum = 0;
var numbers = [65, 44, 12, 4];
numbers.forEach(myFunction);
function myFunction(item) {
sum += item;
document.getElementById("demo").innerHTML = sum;
}