0

I am trying to read the username property of the following JavaScript object and store it inside a variable.

[ RowDataPacket { username: 'admin', password: 'admin' } ]

It is being returned as a result object from an SQL query to a user database. The returned object is called result However, when I try to access its properties with

var sqlusername = result.username

or

var sqlusername = result.RowDataPacket.username

or

var sqlusername = result["username"]

or any other way to access the property,

the value of the variable var is always undefined.

How do I use the username and password properties of the object?

2 Answers 2

1

result is an array with one object in it. Use this:

result[0].username
Sign up to request clarification or add additional context in comments.

1 Comment

Worked. Cheers!
0

Destructure the given result as

const [{ username, password }] = result;

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.