Categories
JavaScript Answers

How to loop through properties in a JavaScript object with Lodash?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *