Open In App

Node forEach() function

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

forEach() is an array function Node 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 an array element after iteration. The program below demonstrates the working of the function:

Example 1: Below is the code example of forEach() function

Output:

cat
dog
fish

Example 2: Below is the code example of forEach() function

Output:

1
2
3
8
7

Similar Reads