- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to transform object of objects to object of array of objects with JavaScript?
To transform object of objects to object of array of objects, use the concept of Object.fromEntries() along with map().
Example
const studentDetails = { 'details1': {Name: "John", CountryName: "US"}, 'details2': {Name: "David", CountryName: "AUS"}, 'details3': {Name: "Bob", CountryName: "UK"}, }; console.log( Object.fromEntries(Object.entries(studentDetails).map(([key, value]) => [key, [value]])) );
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo45.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo45.js { details1: [ { Name: 'John', CountryName: 'US' } ], details2: [ { Name: 'David', CountryName: 'AUS' } ], details3: [ { Name: 'Bob', CountryName: 'UK' } ] }
- Related Articles
- Converting array of objects to an object of objects in JavaScript
- Convert object of objects to array in JavaScript
- Convert object to array of objects in JavaScript
- Converting array of objects to an object in JavaScript
- Convert array of objects to an object of arrays in JavaScript
- JavaScript Converting array of objects into object of arrays
- JavaScript: Sort Object of Objects
- How to merge objects into a single object array with JavaScript?
- Flat a JavaScript array of objects into an object
- Convert an array of objects into plain object in JavaScript
- Splitting an object into an array of objects in JavaScript
- How to compare attributes of different objects in MongoDB object array?
- Sum of array object property values in new array of objects in JavaScript
- How to Sort object of objects by its key value JavaScript
- How to create JavaScript objects using object() constructor?

Advertisements