0

I want to retrieve records from mysql and display data on my page coded in nodejs with format

 [
    ["1262889000000",788,803,783.3,795.65],
    ["1262889000000",788,813,783.3,795.65],
    ["1451500200000",2.85,13,1.05,1.1],
    ........
 ]

my table schema

Column1           |   col2   |   col3   |    col4     |   col5

1262889000000          788       783.3        794          65  
1262889000000          788       813.7        795          65 
...........
........... 

Here is my nodejs code

app.get('/charts/sample1', function(req, res) {

    con.query("select col1,col2,col3,col4,col5 from table1", function(err, data) {
    res.send(data);
    }); 

 });

however currently when run my code i get out in json alng with {key1:value,key2:value,...},

1 Answer 1

2

So you want to map the object values in each row to an array?

Something like this? :

var rows = [{
    Column1: 1262889000000,
    col2: 788,
    col3: 783.3,  
    col4: 794,
    col5: 65
}];

var result = rows.map((row) => {
    return Object.values(row);
});

console.log(result);

Here's a JSFiddle for this: https://jsfiddle.net/y0vpad3b/

Sign up to request clarification or add additional context in comments.

1 Comment

Cool, glad to help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.