Open In App
Related Articles

Lodash _.conformsTo() Method

Improve Article
Improve
Save Article
Save
Like Article
Like

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc.

The _.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: This method accepts two parameters as mentioned above and described below:

  • object: This parameter holds the object to inspect.
  • source: This parameter holds the object of property predicates to conform to.

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

Example 1:

Javascript




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

Output:

true

Example 2:

Javascript




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

Output:

false

Last Updated : 07 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials