![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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' } ] }
Advertisements