matchesProperty source npm

_.matchesProperty(path, srcValue)

Creates a function that performs a deep partial comparison between the value at path of a given object to srcValue, returning true if the object value is equivalent, else false.

Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and strings.

Arguments

  1. path (Array|string)

    The path of the property to get.

  2. srcValue (*)

    The value to match.

Returns (Function)

Returns the new function.

Example

var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];

_.find(users, _.matchesProperty('user', 'fred'));
// => { 'user': 'fred' }