Categories
JavaScript Answers

How to convert JSON object to JavaScript array?

Spread the love

Sometimes, we want to convert JSON object to JavaScript array.

In this article, we’ll look at how to convert JSON object to JavaScript array.

How to convert JSON object to JavaScript array?

To convert JSON object to JavaScript array, we can use the Object.entries method.

For instance, we write

const jsonData = { "2022-01-21": 1, "2022-01-22": 7 };

console.log(Object.entries(jsonData));

to call Object.entries with the jsonData object to return an array with the key-value pairs of the jsonData object as arrays.

Conclusion

To convert JSON object to JavaScript array, we 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 *