Home > Blockchain >  Console Log Result And Typing the result is different
Console Log Result And Typing the result is different

Time:12-11

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 } ]

But the message reply ( on discord ) returns :

@JADA, [object Object]

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

CodePudding user response:

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.

  • Related