Transforming a JavaScript array into a list of arrays

I have a set of data that I would like to convert into an array list without keys. Can anyone help me with this?

Data

[{
    "time": "01/13 15:50",
    "price": 3000,
    "changeRate": -0.27
},
{
    "time": "01/13 15:40",
    "price": 4000,
    "changeRate": -0.27 
}]

Desired output

 [
    [01/13 15:50, 3000],
    [01/13 15:40, 4000]
  ]

Any assistance is greatly appreciated!

Answer №1

Utilize the map technique to achieve this task effortlessly. This method is designed to convert (or "map") one array into a brand new array. The new array maintains the same length as the original, with its elements being derived from the items in the initial array.

data.map(item => [item.time, item.price]);

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

The VueJS component failed to import successfully

Trying a simple demo to explore VueJS components, but encountering an error when loading the page: Unexpected Token Import in this line import GISView from './components/GISView.vue'; If I remove this line, GISView is not defined. Using Laravel ...

Automatically resizing textures in Three.JS with WebGL

Seeking assistance to overcome a challenge :) I am using Three.JS to showcase high-resolution equirectangular images on a sphere (20000x10000 pixels). Image quality is crucial for my web application, and bandwidth is not a concern. My issue is that ThreeJ ...

difficulty parsing JSON data returned by PHP in a jQuery.ajax request

Utilizing $.ajax to retrieve a JSON response from a php script, I am facing an issue where the data variable logged in the success function shows a properly formatted JSON object. However, when trying to access properties of the data variable, it returns u ...

Creating dynamic scrolling effects using windows.scrollBy in JavaScript

Currently, I am using window.scrollBy in the following way: <script> function scrollWindowup() { window.scrollBy(0,700) } function scrollWindowdown() { window.scrollBy(0,-700) } </script> I am wondering if there is a way to animate th ...

Exploring Symfony2 controller integration with Javascript arguments

I am currently working on a project with Symfony2 and I have a question regarding receiving arguments from a template in a controller. My goal is to take the value of the argument and store it in the database. The argument's value will be generated by ...

Whenever I press a button, my desire is for each picture to seamlessly reposition itself in the exact same spot on the screen

Having some issues with my code. When I click a button, the plan is for the pictures to change one by one to simulate a traffic light sequence. However, when I run the code, all the pictures appear at once without any effect from the button. Any help in ac ...

Iterate through elements in an array and concatenate them into a single line using PHP's spread operator

While it may seem simple, what I'm aiming for is: // an array of various unknown items retrieved from the database $array = ['item1','item2','item3']; // I believe this can be achieved using a For loop, but I'm uns ...

Error encountered when adding arrays due to a segmentation fault resulting in a core dump

My cousin needed help with his homework and I offered to assist. The task was to add two large numbers together using arrays, but I've encountered an issue. Upon running the program, it throws a "segmentation fault (core dumped)" error. It seems like ...

JavaScript - Issue with the OnClick event not triggering

I encountered an issue while trying to change the class of an element using pure Javascript upon clicking it. Even though I have used similar code successfully in the past, this particular instance did not work as expected. Here is the relevant part of the ...

Using Puppeteer and Scrapy, this innovative Web Crawler with Scraper combines the power of both

As a newcomer to web technologies, I am faced with the task of crawling and scraping numerous websites that utilize a combination of React, JavaScript, and HTML. These sites collectively contain approximately 0.1 to 0.5 million pages. My plan is to use Se ...

Access within the identical window (PHP file) as opposed to an Iframe

I am currently working with a PHP file that retrieves data from my database. <?php $cdb = new PDO('mysql:dbname=xxx;host=localhost', 'xxx', 'xxx'); foreach ($cdb->query("SELECT * FROM images ORDER BY posted DESC LIMIT ...

The jQuery mouseout functionality seems to be malfunctioning and not responding as expected

I am currently developing a slider that displays details when the mouse hovers over the logo, and hides the details when the mouse moves away from the parent div. jQuery('.st_inner img').mouseover(function() { jQuery(this).parent().siblings( ...

What is the best way to notify the JSON code below using jQuery?

I have received a JSON response after using the Reverse Geocoding API from Google. The response includes various address components such as route, sublocality, locality, and political information. { "results": [ { "address_components": [ ...

Choose the background color for the alternative tag caption using Jquery by selecting it from an array

I have created a function in the code below to dynamically choose background colors for slideshow captions based on the alt tag of an image. Currently, the array values are randomly selected using Math.random. However, I am looking to have them selected ...

Firebase monitors the authentication status of a user

Trying to maintain a global state in my application based on whether the user is logged in or not has me puzzled. Should I only have a single onAuthStateChanged() in my JavaScript file to monitor state changes and manipulate HTML elements like account deta ...

Chapter 5 of Eloquent JavaScript's 3rd Edition presents Exercise 3

I'm struggling with an exercise in the latest edition of a book, specifically in Chapter 5 which covers Higher-Order Functions. The prompt for the exercise is as follows: "Similar to the some method, arrays also contain an every method. This method r ...

Foreign key is not being posted when submitting the form using Laravel and Vue

My dilemma involves managing two tables. Here is the structure of each: Table one, referred to as "parties", consists of the following fields: public function up() { Schema::create('parties', function (Blueprint $table) { $table-> ...

"JavaScript throws an 'Undefined' error when trying to access a basic

I am struggling with a basic set of HTML and JS files that are not functioning properly, and I can't seem to pinpoint the issue: <html> <head> <script type="text/javascript" src="data.json"></script> < ...

Error encountered upon initializing Node-RED due to the presence of an unexpected token while incorporating the NPM module "file-exists" into the

Currently, I'm in the process of developing an application using Node-RED and I'm looking to incorporate some NPM modules into my project. One particular module from James Thom caught my attention, called node-red-contrib-npm, which automates the ...

jQuery enigma - struggling to get slideUp/slideDown to function

My goal is to utilize jQuery and CSS to display the initial paragraph out of a set of four, and insert a link or button at the conclusion of the first paragraph. Upon clicking on the link or button, my aim is to reveal the remaining three paragraphs in a s ...