forEach() is an array function from Node.js that is used to iterate over items in a given array.
Syntax:
array_name.forEach(function)
Parameter: This function takes a function (which is to be executed) as a parameter.
Return type: The function returns array element after iteration.
The program below demonstrates the working of the function:
Program 1:
const arr = ['cat', 'dog', 'fish']; arr.forEach(element => { console.log(element); }); |
chevron_right
filter_none
Output:
cat dog fish
Program 2:
const arr = [1, 2, 3, 8, 7]; arr.forEach(element => { console.log(element); }); |
chevron_right
filter_none
Output:
1 2 3 8 7
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- AngularJS | angular.forEach() Function
- Nodejs | GM charcoal() Function
- Nodejs | GM implode() Function
- Nodejs | GM sharpen() Function
- Nodejs | GM raise() Function
- Nodejs | GM randomThreshold() Function
- Nodejs | GM blur() Function
- Nodejs | GM contrast() Function
- Nodejs | GM minify() Function
- Nodejs | GM magnify() Function
- Nodejs | GM modulate() Function
- Nodejs | GM monochrome() Function
- Nodejs | GM write() Function
- Nodejs | GM sepia() Function
- Nodejs | GM whitePoint() Function
- Nodejs | GM scale() Function
- Nodejs | GM whiteThreshold() Function
- Nodejs | GM lower() Function
- Nodejs | GM drawEllipse() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

