findByProp()

Looks for the first value in an array whose given property matches the criteria.

This function is valid in v2.8.0 to v2.24.3. This function has been downloaded 63 times.

Parameters

{Array} array
Array to traverse.
{string} propName
Name of the property of each array item to inspect. If no such property exists for any array item that item will simply be skipped.
{*} tester
Criteria by which to test the property of each item in array. If this is a function it will be passed the value of the property and the return value will be coerced to a boolean to see if the property fits the criteria. If this is a regular expression it will be tested against the property to see if the property fits the criteria. Any other type of value will be checked to see if the property is this value to see if it fits the criteria.

Returns

{*}
The first item in array for which tester matches the specified property. If tester never matches any of the properties undefined will be returned.

Required Functions

This function directly requires the following functions which are included automatically:

  • filterByProp()
    Looks for all of the items in an array whose given property matches the criteria.
  • findIndexByProp()
    Looks for the first index in an array whose given property matches the criteria.
  • isNaN()
    Determines whether or not a value is actually NaN. Different from the global isNaN function because it only tests for the presence of the NaN value.
  • typeOf()
    Either gets the type of a value or adds a constructor registering its custom type name.

Requiring Functions

This function is directly required by the following functions:

  • filterByProp()
    Looks for all of the items in an array whose given property matches the criteria.
  • findIndexByProp()
    Looks for the first index in an array whose given property matches the criteria.