Sunday, September 22, 2024
Google search engine
HomeLanguagesJavascriptLodash _.conformsTo() Method

Lodash _.conformsTo() Method

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments