Open In App

Lodash _.isMatch() Method

Last Updated : 27 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.isMatch() 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.

Syntax:

_.isMatch(object, source);

Parameters:

  • object: Object in which source is to be matched.
  • source: Source which is to be matched.

Return Value:

This method returns a Boolean value(Returns true if the source and the given object match, else false).

Example 1: In this example, we are checking whether the given value is present in the given object or not by the use of the lodash _.isMatch() method.

Javascript




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


Output:

true
false

Example 2: In this example, we are checking whether the given value is present in the given object or not by the use of the lodash _.isMatch() method. for empty object it will always return true.

Javascript




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


Output:

true

Example 3: In this example, we are checking whether the given value is present in the given array or not by the use of the lodash _.isMatch() method.

Javascript




// Defining Lodash variable
const _ = require('lodash');
 
let object = [1, 2, 3];
 
// Checking
console.log(_.isMatch(object, [1, 2]));
 
// Checking
console.log(_.isMatch(object, [1, 3]));


Output:

true
false


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads