ForEach in ES6 JavaScript
ForEach Loop
The forEach() method calls a function for each element in an array. The forEach() method is not executed for empty elements. It does not return anything. It has a total of two parameters. One is function() and the other is thisValue which is optional. The function() contains three parameters i,e. first is currentValue, second is an index, and the third is an array.
Syntax:-
array.forEach(function(currentValue, index, array), thisValue)
Parameters Explanation:-
function() | A function to run for each array element. Required. |
currentValue | The value of the current element. Required. |
index | The index of the current element. Optional. |
arr | The array of the current element. Optional. |
thisValue | A value is passed to the function as its this value. Optional. |