Lodash _.matchesProperty() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.matchesProperty method creates a function that performs a partial deep comparison between the value at path of a given object to srcValue, returning true if the object value is equivalent, else false.
Syntax:
_.matchesProperty(path, srcValue)
Parameters : This method accepts two parameter as mentioned above and described below:
- path: [Array/string] The path of the property to get.
- srcValue: The value to match with.
Returns: [Function] It returns the new specified function.
Example 1:
// Requiring the lodash library const _ = require("lodash"); // Using _.matchesProperty() method var geek = [ { 'java': 3, 'python': 5, 'js': 7 }, { 'java': 4, 'python': 2, 'js': 6 } ]; let gfg = _.find(geek, _.matchesProperty('java', 4)); // Storing the Result console.log(gfg) |
Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.
Output:
Object {java: 4, js: 6, python: 2}
Example 2:
// Requiring the lodash library const _ = require("lodash"); // Using _.matchesProperty() method var geek = [ { 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }, { 'a': 8, 'b': 7, 'c': 9 } ]; gfg = _._.find(geek, _.matchesProperty('a', 4)); // Storing the Result console.log(gfg) |
Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.
Output:
Object {a: 4, b: 5, c: 6}



