Array iteration methods traverse through every item within the array:
See Also:
The forEach() method invokes a function (known as a callback function) once for every element in the array.
Example
const numbers = [45, 4, 9, 16, 25]; let txt = “”; numbers.forEach(myFunction); function myFunction(value, index, array) { txt += value + “<br>”; } |
Note that the callback function takes three arguments:
In the provided example, only the value parameter is utilized. The example can be restructured as follows:
Example
const numbers = [45, 4, 9, 16, 25]; let txt = “”; numbers.forEach(myFunction); function myFunction(value) { txt += value + “<br>”; } |