Array.prototype.find()

Here is an example on how to use Array.prototype.find() which has been introduced in ECMAScript 6 as an array method to find an element in the array.

function theFirstEven(number) {
  return !(number % 2); // find even number
}

alert([3, 5, 7, 6, 57].find(theFirstEven));

The above script will output number 6 which is an even number within that array.

Like this post? Kindly share!