Changing object of objects into an array of objects with JavaScript

I am working with this particular data structure:

const info = {
    school1:{city:'medway',points:6},
    school2:{city:'milan',points:8},
    school3:{city:'brooklyn',points:103,
    }

Does anyone know how I can transform it into this JavaScript format:

const transformedData = [
    {name:'school1', city:'medway',points:6},
    {name:'school2', city:'milan',points:8},
    {name:'school3', city:'brooklyn',points:103}
    ]

Answer â„–1

You have the ability to iterate over the properties of the object using a map function.

const data={school1:{location:"medway",score:6},school2:{location:"milan",score:8},school3:{location:"brooklyn",score:103}};
const res = Object.entries(data).map(([name, v]) => ({name, ...v}));
console.log(res);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for properly sending an array in a PHP ajax response

Executing ajax calls after PHP to retrieve an array of JSON data. The necessary information is prepared, but unsure about the correct method of returning them. $files = array(); foreach($db2_databaselist as $db) { $file = new stdClass(); $file-&g ...

Utilizing spine.js in conjunction with haml

Recently, I've been experimenting with spine.js and delving into its view documentation. In particular, the example using eco as the templating engine left me feeling less than impressed. Personally, I much prefer working with haml for my templating n ...

JavaScript error in the Electron browser is causing a glitch

I am a beginner in the world of Node.js, JavaScript, and Electron. My goal is to create a basic application that can open a local HTML file in a browser window. The local file contains some complex embedded JavaScript (TiddlyWiki). Below is a snippet of sa ...

Quantity of events

I'm having trouble getting my code to count the occurrences of each integer entered between 1 and 100. I can't figure out what's wrong with it. Any assistance would be greatly appreciated! public static void main(String[] args) { Scanne ...

What is the best way to eliminate an object from an array of objects that fulfills a specific condition?

Upon receiving an object in my function containing the information below: { "name": "Grand modèle", "description": "Par 10", "price": 0, "functional_id": "grand_modele_par_10", "quantity": 2, "amount": 0 } I must scan the next array of objec ...

What is the correct method for properly loading the GLB model?

I am new to three.js and have some questions that I need help with. First Method: Using three.js to load a model (a duck in glb format). As shown below: https://i.sstatic.net/IsYHG.png Second Method: Utilizing to load the same model As shown below: http ...

Having trouble running classes using Maven test with the Testng.xml file in the terminal, however, it runs smoothly in Eclipse

While I have been successful in running my solution through the testng suit in the Eclipse console, I am facing difficulties executing the testng.xml file via Maven integrated with Sauce Labs in the terminal. Output received on the terminal: ------------ ...

The importance of utilizing an object FormData in Node.js to ensure the proper functioning of multer for file uploads via ajax with jQuery

Currently, I am learning about Node.js and using Multer, AJAX, and jQuery for file uploads. However, I am feeling a bit confused. Let's say I have the following code in an HTML file: <form action="/" method='post' enctype=" ...

Auto-fit HTML Webpage Resizer Simplified

Just finished my very first jQuery project, a simple full-width slider. I've been focusing on HTML & CSS and currently working with C#. The problem is that I don't want the page to be scrollable; I want it to autofit to the webpage. Imagine ope ...

Launching Links in Browser Using Cordova in Android Platform

I am facing an issue with the inAppBrowser on Android. Despite setting it up correctly, using _blank or _system still results in the webpage loading within the app instead of opening in an external browser. Here is the relevant code: <a href="#" rel=" ...

Utilize socket communication with node.js to monitor and identify user

I'm attempting to find a method to unsubscribe from a Redis channel when the user navigates to another page within our website. I have attempted to detect a disconnect socket event when the user clicks on a link, but unfortunately, the event is never ...

Creating a custom filter in an ng-repeat table using AngularJS

Utilizing a custom filter, I am able to filter values in a table based on a specific column. The data is sourced from an array of a multiple select input. For a complete example, please refer to: http://jsfiddle.net/d1sLj05t/1/ myApp.filter('filterM ...

Implementing AJAX notifications in a contact form integrated with PHP, Google reCAPTCHA, and SweetAlert

I've implemented an AJAX script to handle the submission of a basic contact form with Google reCAPTCHA at the end of my HTML. Here's the relevant HTML code: <div class="col-md-6"> <form role="form" id="form" action="form.php" method ...

Is there a method to iterate through dynamically added nested arrays, similar to the Russian Matryoshka dolls?

I am facing a challenge in my Angular TypeScript class where I need to define a function that can loop through dynamically added nested arrays. The issue arises because my template displays a custom Kendo grid which requires me to traverse a type of "Matri ...

Tips for managing documents from mongoDB with _bsontype attributes

Hey there, I'm currently working with a JSON array that I retrieved from querying documents in mongoDB. However, I've encountered a strange behavior that I can't quite figure out: in key: _bsontype |value: ObjectID in key: id |value: S÷¯à ...

What is the best location to register RegisterClientScriptBlock within ASP.NET?

What is the optimal location within an asp.net page or code behind to utilize the RegisterClientScriptBlock function? ...

Setting Max or Min Date to Today for Date Input in Angular 2 and Ionic 2

<input class="alert-input date-input" #dob="ngModel" name="dob" max="2018-03-07" [(ngModel)]="leadDetail.dob" type="date"></div> Is there a way to dynamically set the max date to today instead of 2018-03-07? I have tried a couple of methods b ...

Modify a data value when another one is updated

Within my Vue.js data, I have a component that generates form inputs. You can view a live version of this component here. The data structure is as follows: data: { providerData: { archive_cost: { legend: 'Warehouse cost&apos ...

If the array's size is greater than 2, initialize the array to an empty

@ad = [2, 5, 5] if @ad.size < 2 @ad = [] end @ad # => [2, 5, 5] What could be causing @ad to not be an empty array ([])? My intention is to keep track of the last two records in an array and if they happen to be identical, a new record should repl ...

AngularJS issue: [filter:notarray] The expected data type was an array, but instead received: {} while using a filter within an ng

I'm working on populating an HTML table by making an angular request to an API using the ng-repeat directive. The HTML page loads first, and then the data is fetched from the API to fill the table once the response is received. When I include a filter ...