Open In App
Related Articles

Lodash _.matchesProperty() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Lodash _.matchesProperty method creates a function that performs a partial deep comparison between the value at the path of a given object to srcValue, returning true if the object value is equivalent, else false.

Syntax:

_.matchesProperty(path, srcValue);

Parameters :

  • path: [Array/string] The path of the property to get.
  • srcValue: The value to match with.

Return Value:

It returns the new specified function.

Example 1: In this example, we are matching the given property to the given array and returning the matching result by the use of the lodash _.matchesProperty() method.

javascript

// Requiring the lodash library 
const _ = require("lodash");
 
// Using _.matchesProperty() method
let 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)

                    

Output:

Object {java: 4, js: 6, python: 2}

Example 2: In this example, we are matching the given property to the given array and returning the matching result by the use of the lodash _.matchesProperty() method.

javascript

// Requiring the lodash library 
const _ = require("lodash");
 
// Using _.matchesProperty() method
let 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)

                    

Output:

Object {a: 4, b: 5, c: 6}


Last Updated : 30 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads