Array.forEach() is a method in JavaScript that is used to iterate over the elements of an array. The method takes a callback function as an argument, which is executed once for each element in the array. The callback function takes three arguments: the current element, the index of the current element, and the array being traversed.
Here is an example of how to use Array.forEach():
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(function(element, index, array) {
console.log(element, index, array);
});
This will output:
1 0 [1, 2, 3, 4, 5]
2 1 [1, 2, 3, 4, 5]
3 2 [1, 2, 3, 4, 5]
4 3 [1, 2, 3, 4, 5]
5 4 [1, 2, 3, 4, 5]
In this example, the callback function takes three parameters, the current element, the index of the current element and the array being traversed. Here the function will be called for each element in the array and the element, index, and array are passed as arguments to the callback function.