Open In App

Lodash _.conformsTo() Method

Lodash _.conformsTo() method is used to check if the given object conforms to the given source by invoking the predicate properties of the source with the corresponding property values of the object. It returns true if it conforms, else false.

Syntax:

_.conformsTo( object, source );

Parameters:

Return Value:

This method returns true if the object conforms, else false.



Example 1: In this example, we are checking whether the given condition is satisfying to the given object or not and printing the result in the console.




// Defining Lodash variable
const _ = require('lodash');
 
// Initializing a object
let object = { 'gfg': 5, 'GFG': 10 };
 
// Calling the _.conformsTo() functions
_.conformsTo(object,
    {
        'gfg': function (n) { return n > 1; }
    }
);

Output:



true

Example 2: In this example, we are checking whether the given condition is satisfying to the given object or not and printing the result in the console.




// Defining Lodash variable
const _ = require('lodash');
 
// Initializing a object
let object = { 'gfg': 5, 'GFG': 10 };
 
// Calling the _.conformsTo() functions
_.conformsTo(object,
    {
        'GFG': function (n) { return n > 12; }
    }
);

Output:

false

Article Tags :