JavaScript Array find() Method (original) (raw)

Last Updated : 09 Jan, 2025

The find() method in JavaScript looks through an array and returns the first item that meets a specific condition you provide. If no item matches, it returns **undefined. It skips any empty space in the array and doesn’t alter the original array.

**Syntax:

array.find(function(currentValue, index, arr), thisValue)

**Parameters:

**Return value:

Different Examples of find() Method

**Example 1: In this example we searches for the first positive element in the array. The find() method iterates through the array, returning the first element greater than 0. It logs the result to the console.

JavaScript `

// Input array contain some elements. let array = [-10, -0.20, 0.30, -40, -50];

// Method (return element > 0). let found = array.find(function (element) { return element > 0; });

// Printing desired values. console.log(found);

`

**Example 2: In this example we searches for the first element in the array greater than 20. It uses the find() method to iterate through the array and returns the first element that satisfies the condition. Finally, it logs the result (30) to the console.

JavaScript `

// Input array contain some elements. let array = [10, 20, 30, 40, 50];

// Method (return element > 10). let found = array.find(function (element) { return element > 20; });

// Printing desired values. console.log(found);

`

**Example 3: In this example we aims to find the first element in the array greater than 4. It employs the find() method, iterating through the array until a matching element is found. It logs the result (`7`) to the console.

JavaScript `

// Input array contain some elements. let array = [2, 7, 8, 9];

// Provided testing method (return element > 4). let found = array.find(function (element) { return element > 4; });

// Printing desired values. console.log(found);

`

**Supported Browsers: