Javatpoint Logo
Javatpoint Logo

JavaScript Array forEach() method

The JavaScript array forEach() method is used to invoke the specified function once for each array element.


The forEach() method is represented by the following syntax:


callback - It represents the function that test the condition.

currentvalue - The current element of array.

index - It is optional. The index of current element.

arr - It is optional. The array on which forEach() operated.

thisArg - It is optional. The value to use as this while executing callback.



JavaScript Array forEach() method example

Let's see some examples of forEach() method.

Example 1

Here, we will print the array elements using forEach().

Test it Now


C C++ Python

Example 2

Here, we will print the Fibonacci series with the help of forEach() method.

Test it Now


10 28 40 60

Next TopicJavaScript Array

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA