Use findIndex
as other previously written. Here's the full example:
function find(arr, predicate) {
foundIndex = arr.findIndex(predicate);
return foundIndex !== -1 ? arr[foundIndex] : null;
}
And usage is following (we want to find first element in array which has property id === 1
).
var firstElement = find(arr, e => e.id === 1);