JavaScript Array find()
JavaScript Array find()
The find() method is used to return the value of the first element that passes a test. It will execute a function for each array element. It returns undefined if no elements are found and do not execute the function for empty elements. It does not change the original array.
Syntax:-
Its syntax is:- array.find(function(currentValue, index, arr),thisValue)
Return:-
Its return is:- the value of the first element that passed the test.
Further Explanation:-
Parameter | Description |
function() | Required. A function to run for each array element. |
currentValue | Required. The value of the current element. |
index | Optional. The index of the current element. |
arr | Optional. The array of the current element. |
thisValue | Optional. A value is passed to the function as this value. Default is undefined. |