Lodash _.conforms() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.conforms() method of Util is used to create a function that calls the predicate properties of the source with the analogous property values of a stated object, which returns true if all the predicates are true else returns false.
Syntax:
_.conforms(source)
Parameters: This method accepts single parameter as described below:
-
source (Object): It is the object of property predicates which is to be conform.
Return Value: This method returns the new specified function.
Example 1:
// Requiring the lodash library const _ = require('lodash'); Â Â // Initializing an object var object = [ Â Â { 'x': 2, 'y': 3 }, Â Â { 'x': 5, 'y': 6 } ]; Â Â // Calling _.conforms() function with its parameter let newfunc = _.filter(object, _.conforms({ 'y': function(n) {Â return n > 3; } })); Â Â // Displays output console.log(newfunc); |
Output:
[ { x: 5, y: 6 } ]
Example 2: Â
// Requiring the lodash library const _ = require('lodash'); Â Â // Initializing an object var object = [ Â Â { 'GfG': 13, 'zambiatek': 5 }, Â Â { 'GfG': 7, 'zambiatek': 4 } ]; Â Â // Calling _.conforms() function with its parameter let newfunc = _.filter(object, _.conforms({ 'GfG': function(n) {Â return n > 13; } })); Â Â // Displays output console.log(newfunc); |
Output:
[]
Here, nothing is returned as the stated condition is not satisfied.
Reference: https://lodash.com/docs/4.17.15#conforms



