Lodash _.conformTo() Method
Last Updated :
10 Sep, 2020
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.
const _ = require( "lodash" );
var object = { 'p' : 11, 'q' : 9 };
let conform_data = _.conformsTo(object, {
'q' : function
(n) { return n > 1; }
});
console.log(conform_data);
|
Output:
true
Example 2:
const _ = require( "lodash" );
var object = { 'x' : 1, 'y' : 3 };
let conform_data = _.conformsTo(object, {
'q' : function
(n) { return n > 3; }
});
console.log(conform_data);
|
Output:
false
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Share your thoughts in the comments
Please Login to comment...