HTML DOM NodeList.forEach() Method
The forEach() method of the NodeList interface calls the callback given in parameter once for each value pair in the list, in insertion order.
- Callback: A function to execute on each element of NodeList. It accepts 3 parameters:
- currentValue: The current element to be processed in NodeList.
- currentIndex (Optional): The index of the currentValue being processed in NodeList.
- listobj (Optional): The NodeList on which forEach() is being applied.
- thisArg (Optional): Value to use as this when executing callback.
Return value: This method returns undefined.
Example: In this example, we will create a NodeList and hence will get all values from NodeList using this method.
Before Clicking Button:
After Clicking Button: Elements are called using forEach().
In the console: Element Values can be seen.
- Google Chrome