Node.js | forEach() function
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 | DNS
- Web-Socket in NodeJS
- Nodejs | DNS | setServers()
- Nodejs | Jimp
- Difference between NodeJS and AngularJS
- Nodejs | Web Crawling using Cheerio
- Encrypting Data in NodeJS
- Dockerizing a simple Nodejs app
- Signup Form Using Nodejs and MongoDB
- Cowsay in Nodejs using Requests library
- Nodejs – Connect Mysql with Node app
- NodeJs - Handling invalid routes
- Nodejs - Connect MongoDB with Node app using MongooseJS
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.