Javatpoint Logo
Javatpoint Logo

JavaScript Array find() method

The JavaScript array find() method returns the first element of the given array that satisfies the provided function condition.

Syntax

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

Parameter

callback - It represents the function that executes each element.

value - The current element of an array.

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

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

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

Return

The value of first element of the array that satisfies the function condition.

JavaScript Array find() method example

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

Example 1

Let's see a simple example of find() method.

Test it Now

Output:

22

Example 2

In this example, we will find a prime number using find() method.

Test it Now

Output:

7

Next TopicJavaScript Array




Please Share

facebook twitter google plus pinterest

B.Tech / MCA


Learn Latest Tutorials