'Cannot get Object from RowDataPacket

I have this code on my router.js:

conexion.query('SELECT * FROM log WHERE id= ?',[id],(error,results)=>{
var user = results[0].user}) 

so when I run this terminal says 'TypeError: Cannot read properties of undefined (reading 'user')'

I know that results is a RowDataPacket cause if I do a console.log(results) it's comes in a RowDataPacket form, so the code above makes sense to me to be right, but obviously I'm missing something.

The log table from mysql have 4 fields (id,user,date,error).

I have try this format before and it worked, even with the same table but others fields.

Already have checked that user is a varchar and if I try something like

var user = results[1].user

nothing show up from that.

And cannot try to 'SELECT user FROM log..' cause gonna need the other fields later in the code too and even the result still comes in a RowDataPacket from.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source