Javascript has a rich set of inbuilt functions to work with string and arrays. Find() is also an inbuild function that returns a value of the first element in an array that satisfied the provided testing function. If there is no match in the array, undefined is returned.
It is a pure function because it does not mutate the array on which it is called. Instead, it returns a value that satisfies the condition.
Following is the syntax of the array find() method.
arr.find(callback(element[, index[, array]])[, thisArg])
callback: It is the function which execute on each value in the array, it takes 3 arguments
element: This is the current element in the array.
index(optional): The index of the current element in the array.
array(optional): The array on which find was applied.
thisArg(optional): This is an Object to use as this inside callback.
Other Examples:
Following is an example to find an object in an array by one of its properties.
Achieving the same task using arrow function and destructuring
Click here to find more details about this function.
Let me know your thoughts over email demo.jsonworld@gmail.com. I would love to hear them and If you like this article, share it with your friends.
Thanks!