.Find method in JavaScript
Let’s start with. find inbuilt function.
The Find () method is used to iterate through the array and complete the find conditioned function by creating new array, without changing the given parameter Array.
Syntax
arr.find(callback(currentValue), thisArg)
Let’s see an example of Why FIND is used:
Explanation of code
//Here is an Array
let array = [10, 8 15 18, 9]
for(let i = 0;i<array.length ; i++){
if(array[i] > 15){
console.log(array[i])
}
}
Recommended by LinkedIn
💡 YES!!!!! For better use and efficient work, Find was made as inbuilt function. So, let’s see What it is!!!!
Explanation of code
//Here is an Array
let array = [10, 8, 15, 18, 9]
const findTheNum = (array) =>array.find(num => num > 15)
console.log(findTheNum(array))
// output = 18
💡 YES!!!!! Just in one line we have finished the array problem. By using FIND Function
Key Points of Find method
💡 Can we use the objects????
Yes!!! we can but objects should be encased within the List!