Open In App

Lodash _.conformTo() Method

Last Updated : 10 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads