Sometimes, we want to use filter with nested objects with Lodash.
In this article, we’ll look at how to use filter with nested objects with Lodash.
How to use filter with nested objects with Lodash?
To use filter with nested objects with Lodash, we can filter
with the nested property values.
For instance, we write
const filtered = _.filter(summary.data, ["category.parent", "Food"]);
to call filter
with the summary.data
array and an array with the property path and the value to check for in the property path.
Therefore, filtered
is an array with the entries in summary.data
that has the category.parent
property set to 'Food'
.
Conclusion
To use filter with nested objects with Lodash, we can filter
with the nested property values.