The pickBy
function from lodash is used to filter out an object's properties based on a given predicate function. It returns a new object with only the properties that pass the predicate.
Here's an example usage of the pickBy
function in JavaScript:
index.tsx207 chars9 lines
In this example, we import the lodash library and define an object obj
with three properties. We then use pickBy
to create a new object filteredObj
with only the properties that are of type number
. The predicate function checks each property's value and key and returns true
if the value is a number. Finally, we log the filteredObj
, which contains the a
and c
properties from the original object.
gistlibby LogSnag