JavaScript - Arrays - find


// JavaScript - Array.prototype.find():
The find() method returns a value of the first element in the array that 
satisfies the provided testing function. Otherwise undefined is returned.

arr.find(callback[, thisArg])

callback: Function to execute on each value in the array, taking three arguments:
1. element: The current element being processed in the array.
2. index: The index of the current element being processed in the array.
3. array: The array find was called upon.

thisArg: Optional. Object to use as this when executing callback.

function isBigEnough(element) {
  return element >= 15;
[12, 5, 8, 130, 44].find(isBigEnough); // 130

The find method executes the callback function once for each element present in 
the array until it finds one where callback returns a true value. If such an 
element is found, find immediately returns the value of that element. Otherwise, 
find returns undefined. callback is invoked only for indexes of the array 
which have assigned values; it is not invoked for indexes which have been 
deleted or which have never been assigned values.

The callback is invoked with three arguments: the value of the element, the 
index of the element, and the Array object being traversed.

If a thisArg parameter is provided to find, it will be used as the this for each 
invocation of the callback. If it is not provided, then undefined is used.

The find method does not mutate the array on which it is called.

The range of elements processed by find is set before the first invocation of 
callback. Elements that are appended to the array after the call to find begins 
will not be visited by callback. If an existing, unvisited element of the array 
is changed by callback, its value passed to the visiting callback will be the 
value at the time that find visits that element's index; elements that are 
deleted are not visited.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License