Thursday, June 18, 2026
HomeLanguagesJavascriptLodash _.matchesProperty() Method

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}
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6898 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6965 POSTS0 COMMENTS