

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- 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
- JavaScript: Sort Object of Objects
- Converting array of objects to an object in JavaScript
- JavaScript Converting array of objects into object of arrays
- Convert array of objects to an object of arrays in JavaScript
- Flat a JavaScript array of objects into an object
- Splitting an object into an array of objects in JavaScript
- Convert an array of objects into plain object in JavaScript
- How to merge objects into a single object array with JavaScript?
- Sum of array object property values in new array of objects in JavaScript
- How to compare attributes of different objects in MongoDB object array?
- How to Sort object of objects by its key value JavaScript
- Update array of objects with JavaScript?
Advertisements