Open In App

Lodash _.isMatchWith() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.isMatchWith() method performs a partial deep comparison between object and source to determine if the object contains equivalent property values. Due to partial comparisons, it will match empty array and empty object source values against any array or object value, respectively. This method accepts another function as “customizer” which is invoked to compare values.

Syntax:

_.isMatchWith( object, source, [customizer] )

Parameters:

  • object: Object in which source is to be matched.
  • source: Source which is to be matched.
  • customizer: Function used to customize comparisons.

Return Value:

This method returns a boolean value. Returns true if the source and the given object matches, else false.

Example 1: In this example, we are checking whether the given value matches the object or not.

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
let object = { 'Geeks': "GfG", 'Geeks2': "GfG2" };
 
function fun() {
    return true;
}
 
// Checking
console.log(_.isMatch(object, { 'Geeks2': "GfG2" }, fun));
 
// Checking
console.log(_.isMatch(object, { 'Geeks': "GfG2" }, fun));


Output:

true
false

Example 2: In this example, for checking with an empty source this method returns true.

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
let object = { 'Geeks': "GfG", 'Geeks2': "GfG2" };
 
function fun() {
    return true;
}
 
// Checking
console.log(_.isMatch(object, {}, fun));


Output:

true


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