Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js forEach() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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);
});

Output:

cat
dog
fish

Program 2:




const arr = [1, 2, 3, 8, 7];
arr.forEach(element => {
  console.log(element);
});

Output:

1
2
3
8
7
My Personal Notes arrow_drop_up
Last Updated : 13 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials