Describing the find Operation
- The
findoperation is used for returning the first element of an array satisfying a condition -
It accepts a callback function with the following arguments:
currentValue:Current element processed in the arrayindex: Optional index ofcurrentValuearray: Optional array that is calledthisArg: Optional value to use asthis
Defining an Array
let fruits = ["Apple", "Banana"];
console.log(fruits.length);
// 2Using the find Operation
// Regular function
fruits.find(function(item, index, array) {
return item.length < 10;
})
// "Apple"
// Arrow function
fruits.find(item => item.length < 10);
// "Apple"Previous
Next