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.