The _.isMatch(object, source)
function from Lodash is used to check if an object
conforms to a source
by invoking _.conformsTo(object, _.conforms(source))
.
Here's an example of how to use the _.isMatch
function:
index.tsx149 chars7 lines
In this example, the _.isMatch
function is used to check if object
matches the source
. Since object
has a key-value pair b: 2
, which matches the source
, the _.isMatch
function returns true
.
Note that the _.isMatch
function does not handle nested objects. If you need to check nested objects, you can use _.matches
instead of _.conforms
.
index.tsx211 chars8 lines
In this example, the source and object have the same structure, but the _.isMatch
function returns false
because it does not handle nested objects. We can use _.matches(source)
to create a function that returns true
if the object matches the source, and then pass that function to _.conformsTo(object, ...)
to check if the object conforms to the source.
gistlibby LogSnag