matches source npm

_.matches(source)

Creates a function that performs a deep partial comparison between a given object and source, returning true if the given object has equivalent property values, else false.

Note: This method supports comparing arrays, booleans, Date objects, numbers, Object objects, regexes, and strings. Objects are compared by their own and inherited enumerable properties. For comparing a single value see _.matchesProperty.

Arguments

  1. source (Object)

    The object of property values to match.

Returns (Function)

Returns the new function.

Example

var users = [
  { 'user': 'barney', 'age': 36, 'active': true },
  { 'user': 'fred',   'age': 40, 'active': false }
];

_.filter(users, _.matches({ 'age': 40, 'active': false }));
// => [{ 'user': 'fred', 'age': 40, 'active': false }]