Answer the question
In order to leave comments, you need to log in
How to convert an array received from mysql to another form?
Code (node.js):
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '*********',
user : '*********',
password : '**********',
database : '**********'
});
module.exports = (arg, callback) => {
connection.connect();
connection.query('SELECT user FROM users', function(err, rows, fields) {
if (err) throw err;
return callback('Текст: ' + JSON.stringify(rows));
});
connection.end();
}
Answer the question
In order to leave comments, you need to log in
Something like this.
if (err) throw err;
var array = new Array();
for (var t in rows)
array.push(t['user']);
return callback('Text: ' + JSON.stringify(array));
var mysqlText = '[{"user":317959591},{"user":222222},{"user":3333333}]';
var mysqlArray = JSON.parse(mysqlText);
var array = mysqlArray.map(function(i){ return i.user });
console log(array);
// [317959591, 222222, 3333333]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question