Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Console Log Result And Typing the result is different

When I run this Javascript code that selects the id where the username is admin.

conauth.connect(function(err) {
 if (err) throw err;
  conauth.query("SELECT id FROM account WHERE username = (?)",[object], function (err, result, fields) {
    if (err) throw err;
    console.log(result)
    message.reply(result)
  });
});

The Console result is Correct

[ RowDataPacket { id: 8 } ]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But the message reply ( on discord ) returns :

@JADA, [object Object]

I Only Want the actual result which is 8 as a number only.

>Solution :

In this situation, result is an array with a single object value that contains an id property.

To return just the id property of the object, use this:

message.reply(result[0].id) // 8

result[0] targets the first value in the array and .id targets the id property of that value.

Hope this helps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading