Categories
JavaScript Answers

How to transform object to array with Lodash?

Spread the love

Sometimes, we want to transform object to array with Lodash.

In this article, we’ll look at how to transform object to array with Lodash.

How to transform object to array with Lodash?

To transform object to array with Lodash, w e can use the Object.entries method.

For instance, we write

const arr = Object.entries(obj).map(([key, value]) => ({ key, value }));

to get each property of obj as a key-value pair array.

And then we put the key and value into their own array with map to create an array with the key and value properties.

Conclusion

To transform object to array with Lodash, w e can use the Object.entries method.

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 *