find() array method in javascript

Array methods were introduced in javascript in ES5. Before this, every array iteration was performed by loops. But after the introduction of array methods to perform array operations, work on an array has become very easy without the implementation of extra coding.

Here we will discuss some array methods.

find()

This method gives the first condition passed element. If no elements pass the given condition it gives an undefined return value. It is not valid for empty arrays. It does not change the original array.

syntax

array.find(function (currentValue, currentIndex, array)=>statements)

Parameters

currentValue

It specifies the value of the current element. It is a required parameter.

currentIndex(optional)

It specifies the index of the current element.

array(optional)

It specifies the array on which every method is applied.

Return Value

It returns undefined if the condition is not satisfied by any element. If the condition is satisfied by any elements it gives true.

Example

if we want to search for a specific name in the array of strings.

Output: