Thursday, September 4, 2025
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

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS