findWhere()

Finds the first item in an array which matches the specified criteria.

This function is valid in v2.23.0 to v2.24.3. This function has been downloaded 36 times.

Parameters

{Array|null|undefined} array
If an array is given each item will be traversed from start to end to find the first item which matches the given rules. If undefined or null is given then a partial findWhere() function is created with just the rules that were given which will accept only the array parameter.
{…Array} ruleX
An array containing (1) the path, (2) optionally the comparator as a string and (3) the value to check the variable at that path against. Each part of the path should be a separate item in the array. For example [\"details\", \"age\", \">=\", 18] can be used to make sure that array[index].details.age >= 18 occurs. If no comparator is supplied === will be used. If one of the paths doesn't exist the entire test will fail.

Returns

{*}
The first value in array which passes all of the specified rules.

Required Functions

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

  • findWhereNot()
    Finds the first item in an array which does not match the specified criteria.
  • indexWhere()
    Finds the position of the first item in an array which matches the specified criteria.
  • indexWhereNot()
    Finds the position of the first item in an array which does not match the specified criteria.
  • indicesWhere()
    Finds the positions of the items in an array which match the specified criteria.
  • indicesWhereNot()
    Finds the positions the items in an array which do not match the specified criteria.
  • lastIndexWhere()
    Finds the position of the last item in an array which matches the specified criteria.
  • lastIndexWhereNot()
    Finds the position of the last item in an array which does not match the specified criteria.
  • lastWhere()
    Finds the last item in an array which matches the specified criteria.
  • lastWhereNot()
    Finds the last item in an array which does not match the specified criteria.
  • slice()
    Slice does not modify the original array, but instead returns a shallow copy of elements from the original array.
  • testFor()
    Creates functions for testing values.

Requiring Functions

This function is directly required by the following functions:

  • findWhereNot()
    Finds the first item in an array which does not match the specified criteria.
  • indexWhere()
    Finds the position of the first item in an array which matches the specified criteria.
  • indexWhereNot()
    Finds the position of the first item in an array which does not match the specified criteria.
  • indicesWhere()
    Finds the positions of the items in an array which match the specified criteria.
  • indicesWhereNot()
    Finds the positions the items in an array which do not match the specified criteria.
  • lastIndexWhere()
    Finds the position of the last item in an array which matches the specified criteria.
  • lastIndexWhereNot()
    Finds the position of the last item in an array which does not match the specified criteria.
  • lastWhere()
    Finds the last item in an array which matches the specified criteria.
  • lastWhereNot()
    Finds the last item in an array which does not match the specified criteria.