Lodash _.isMatch() Method
Last Updated :
27 Oct, 2023
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
const _ = require( 'lodash' );
let object = { 'Geeks' : "GfG" , 'Geeks2' : "GfG2" };
console.log(_.isMatch(object, { 'Geeks2' : "GfG2" }));
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
const _ = require( 'lodash' );
let object = { 'Geeks' : "GfG" , 'Geeks2' : "GfG2" };
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
const _ = require( 'lodash' );
let object = [1, 2, 3];
console.log(_.isMatch(object, [1, 2]));
console.log(_.isMatch(object, [1, 3]));
|
Output:
true
false
Share your thoughts in the comments
Please Login to comment...