Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptLodash _.conformTo() Method

Lodash _.conformTo() 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 checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object and this method is equivalent to _.conforms when source is partially applied.

Syntax:

_.conformsTo(object, source)

Parameters: This method accepts two parameters as mentioned above and described below:

  • object: It is the object that the method is to inspect.
  • source: It is the object of property predicates to conform to.

Return Value: This method returns the object of property predicates to conform to.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array 
var object = { 'p': 11, 'q': 9 };
   
// Using the _.conformsTo() method
let conform_data =  _.conformsTo(object, { 
    'q': function
  
    (n) { return n > 1; } 
});
  
// Printing the output 
console.log(conform_data);


Output:

true

Example 2:




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array 
var object = { 'x': 1, 'y': 3 };
   
// Using the _.conformsTo() method
   
let conform_data =  _.conformsTo(object, { 
    'q': function
  
    (n) { return n > 3; } 
});
  
// Printing the output 
console.log(conform_data);


Output:

false

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

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