sall brown sall brown - 5 months ago 159
Node.js Question

Javascript array parsing

var usersRows = [];
connection.query('SELECT * from users', function(err, rows, fields) {
if (!err) {
rows.forEach(function(row) {
usersRows.push(row);
});
console.log(usersRows);
}
else {
console.log('Error while performing Query.' + err);
}
});


It returned to me:

var usersRows = [ [ RowDataPacket { id: 1, name: 'sall brwon', number: '+99999999\r\n' } ] ];


I need to parse this and remove
rowdatapacket
; I need result like this:

userRows = { id: 1, name: 'my name is', number: '+999999\r\n' };

Answer

Have you tried

userRows = RowDataPacket;