Generating a personalized list of objects from JSON information

My json objects array contains the following data:

[{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":10},{"SensorID":2,"Temperature":34.0,"Humidity":43.0,"Carbon":87.0,"DateTime":"2017-03-09T12:00:00","ID":12},{"SensorID":2,"Temperature":23.0,"Humidity":89.0,"Carbon":65.0,"DateTime":"2017-03-09T12:00:00","ID":13},{"SensorID":2,"Temperature":34.0,"Humidity":56.0,"Carbon":87.0,"DateTime":"2017-03-08T10:07:00","ID":16},{"SensorID":2,"Temperature":87.0,"Humidity":34.0,"Carbon":23.0,"DateTime":"2017-03-08T10:07:00","ID":18},{"SensorID":2,"Temperature":44.0,"Humidity":67.0,"Carbon":43.0,"...

I am looking to transform this array into a new format like

[[Date.UTC(2015,1,13),0.8783],
    [Date.UTC(2015,1,15),0.8774],
    [Date.UTC(2015,1,16),0.8807],
    [Date.UTC(2015,1,17),0.8762],
    [Date.UTC(2015,1,18),0.8774],
    [Date.UTC(2015,1,19),0.8798],
    [Date.UTC(2015,1,20),0.8787],]]

I need to convert my original array into the second format to use in highstock charts. How can I achieve this transformation?

Answer №1

One possible solution could involve utilizing the map method. The concept behind this approach is to iterate through each element in a list and apply a specific function to create a new list.

data  = [{"SensorID":4,"Temperature":29.0,"Humidity":62.0,"Carbon":75.0,"DateTime":"2017-09-15T08:45:00","ID":24} ... ]

newArray = data.map(function(item) {
   // Additional logic can be inserted here...
   return new Date(item.DateTime);
})

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

What causes an error in returning an entity with a one-to-many relationship in a web API?

Hey guys, I have a One to Many relationship with the same class called User. In my web API's GET method, I am returning just one instance of the user and it seems to be working fine as long as there are no issues. User ID | Name 0 | A 1 | B ...

Building a matrix-esque table using d3.js reminiscent of HTML tables

I would like to generate a table resembling a matrix without numerical values. 1. Here is an example of my database table: | CODE | STIL | SUBSTIL | PRODUS | |------|-------|----------|---------| | R | stil1 | substil1 | produs1 | | R | stil1 | s ...

What are the steps to fix the CORS problem when sending AJAX requests from a frontend to a Flask server?

My current project involves creating a web application with Flask for the backend and JavaScript for the frontend. However, I'm encountering challenges with CORS policy when attempting to send AJAX requests from my frontend to the Flask server. Below ...

Utilizing AngularJS and ADAL.JS to Define Resource ID (Audience)

Is there a way to utilize adal.js within AngularJS to obtain a bearer token for the audience https://management.azure.com through JavaScript? I have created a client application in Azure AD and configured its permissions to allow access to the "Windows Az ...

Tips for utilizing the nth-child selector to exclude hidden divs

I am facing an issue with displaying random blocks in rows. Each time a block falls into a new row, I want it to have a different style. However, when the user clicks on a button to hide certain blocks using display:none, the problem arises because the nth ...

Updating MySQL Database in Laravel 5.2 with JSON Data retrieved from MongoDB

Is there a way to update a MySQL Database table using data retrieved from MongoDB? I currently have a function that fetches data from MongoDB $recordid = '9depnuDz1XHl'; $mongodata = MongoDataPull::find($recordid); Upon executing the code: r ...

Tips for stopping automatic redirection to the root page when refreshing in Ionic 2/3

While developing new pages in Ionic 2, I am facing an issue where refreshing the page always redirects to the root index page. How can I prevent this behavior? One Scenario: For example, I have created a login page and a welcome page. After logging in, if ...

After updating the name of an input control for validation, the ASP.NET validators are no longer functioning properly

Adding "runat=server" to an input control allows for ASP.NET validators to be specified, but it can create complications when dynamically adding rows with JavaScript. Each input control must follow a specific naming convention, like "inputControl_" + count ...

When a row is clicked, retrieve the data specific to that row

I have implemented a data-grid using react-table where I pass necessary props to a separate component for rendering the grid. My issue is that when I click on a particular row, I am unable to retrieve the information related to that row using getTrProps. ...

I am consistently encountering issues with the ListView Builder returning null values

I am facing an issue with the following code snippet: class HonPage extends StatefulWidget { final Status? status; HonPage({Key? key, this.status}) : super(key: key); @override _HonPageState createState() { return _HonPageState(); } } clas ...

Display the JSON outcome with console.logging

As I delve into the world of APIs, JSON, and JQuery, I've encountered a roadblock. How can I retrieve the following information, "name: The Old Mill Cafe," and log it to the console from my JQuery call? Below is my current code snippet: $(document). ...

Developing dynamic 3D cubes

In my latest project, I am attempting to construct a unique structure composed of 3D cubes arranged in a stacked formation. Each of the individual cubes within this structure is designed to be interactive for users. When a user hovers over a cube, it trigg ...

Exploring the process of web scraping from dynamic websites using C#

I am attempting to extract data from using HtmlAgilityPack. The website is dynamic in nature, displaying content after the page has fully loaded. Currently, my code retrieves the HTML of the loading bar using this method, but encounters a TargetInvocation ...

Can I use javascript/jquery to alter the direction of text in each line?

Looking for assistance with changing text direction on each new line. For instance: text left-to-right text right-to-left text left-to-right text right-to-left... etc. I would like the text direction to change with each word-wrap: break-word. Any help w ...

A step-by-step guide to invoking a function upon submitting a form with an external JavaScript file

How can I execute a function when the user submits a form using an external JavaScript file? index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>example</title> ...

Error: Unable to access the 'rotation' property of an undefined object in the animate function on line 266 of index.html, at line 287 of index.html

I am facing an error when trying to animate a model with rotation or position in my code. I attempted to create an init function to run everything, but it did not resolve the issue. The error only appears during animation; once the animation stops, the e ...

The HTML table fails to refresh after an Ajax request has been made

I am currently utilizing Ajax to delete a row from the Roles table. The functionality allows the user to add and delete roles using a link for each row. While the deletion process works properly and removes the row from the database, the table does not get ...

The error message indicates an issue with a Perl hash containing arrays located at memory address 0x7ff4bbb0c7b

My code runs without any fatal errors, but the output is wrong. I start by creating a hash of arrays and then search for sequences in a file based on the keys in the hash. If the sequence is found as a key in the hash, I print the key and its associated va ...

Transforming iframe programming into jquery scripting

Currently, I have implemented an Iframe loading the contents within every 5 seconds. It works well, however, there is a consistent blinking effect each time it loads which can be quite bothersome. I am looking to replace the iframe with a scrolling div so ...

What is the best way to automatically populate the date and time fields in PHP MySQL without manual input?

Is there a way to automatically populate these two input fields without any manual input? <input type="time" name="Time" id="Time" value="" /> I am looking for a solution to automatically fill the date and ti ...