ES6 - Array.find


This function returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.


Given below is the syntax for the array method find(), where, thisArg is an optional object to use as this when executing the callback and callback is the function to execute on each value in the array, taking three arguments as follows −

  • element − The current element being processed in the array.

  • index − This is optional; refers to the index of the current element being processed in the array.

  • array − This is optional; the array on which find was called.

arr.find(callback(element[, index[, array]])[, thisArg])


   const products = [{name:'Books',quantity:10},
   console.log( products.find(p=>"Books"))

The output of the above code will be as mentioned below −

{name: "Books", quantity: 10}