Lodash - matches method



Syntax

_.matches(source)

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

Arguments

  • source (Object) − The object of property values to match.

Output

  • (Function) − Returns the spec function.

Example

var _ = require('lodash');
var objects = [
   { 'a': 1, 'b': 2, 'c': 3 },
   { 'a': 4, 'b': 5, 'c': 6 }
];
 
var result = _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));

console.log(result);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

[ { a: 4, b: 5, c: 6 } ]
lodash_util.htm
Advertisements