Sometimes, we want to loop through properties in a JavaScript object with Lodash.
In this article, we’ll look at how to loop through properties in a JavaScript object with Lodash.
How to loop through properties in a JavaScript object with Lodash?
To loop through properties in a JavaScript object with Lodash, we use the forOwn function.
For instance, we write
_.forOwn(obj, (value, key) => {});
to call forOwn with obj and a callback that has the value and key of each obj property as parameters.
forOwn only loops through non-inherited properties in obj.
Conclusion
To loop through properties in a JavaScript object with Lodash, we use the forOwn function.