1

I made this code:

con.query("SELECT orgID FROM players WHERE scID = "+socialID+""), function (err, result) {
        if (err) console.log(err)
        console.log(result) 

It returns this:

[ RowDataPacket { orgID: null } ]

Is there any way to make it return just 'null' without having to convert it to a string and parsing it?

1
  • 1
    There is no need to convert into string or parse. result is an array containing a single object, with a single property orgID. You can access it with result[0].orgID Commented Sep 4, 2020 at 11:47

1 Answer 1

1

result[0] is just an object that happens to have been created with RowDataPacket as constructor, but you can access it like a plain object.

If you don't know the name of the field, then get the values of that object using Object.values, and if you expect only one, then access that value with index 0:

Object.values(result[0])[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.