Sometimes, we want to convert object containing objects into array of objects with JavaScript.
In this article, we’ll look at how to convert object containing objects into array of objects with JavaScript.
How to convert object containing objects into array of objects with JavaScript?
To convert object containing objects into array of objects with JavaScript, we can use the Object.values method.
For instance, we write
const data = {
a: { 0: "1" },
b: { 1: "2" },
c: { 2: "3" },
d: { 3: "4" },
};
const newArrayDataOfOjbect = Object.values(data);
to call Object.values with data to return an array of property values from the data object.
Conclusion
To convert object containing objects into array of objects with JavaScript, we can use the Object.values method.