I have JavaScript code below that connect to the database and SELECT table
//Connect to database
var sql = require("mssql");
var config = {
user: '****',
password: '*****',
server: '****',
databse:'****',
};
sql.connect(config)
var request = new sql.Request();
// query to the database and get the records
request.query("select * from Test ")
below is the terminal output.
recordset: [
{ ID: '0 ', Name: 'Test1 ', Age: '80 ' },
{ ID: '1 ', Name: 'Test2 ', Age: '55 ' }
],
So I need to make array below take all data from recordset, so I can use the array in other functions
var users = [{}]
when open the page on the browser the var users should look
users = [
{ ID: '0', Name: 'Test1', Age: '80' },
{ ID: '1', Name: 'Test2', Age: '55' }
]
If you already have recordset
in desired format and you want it to be users
, you can do this:
var users = recordset;