0

I am new to Node server. In my program I fetched some data from data base as

connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, rows)
    {
        var employees = (JSON.stringify(rows));
        console.log("Inside server "+employees  )
    });  

Now in console i got some thing like

[{"user_id":7,"username":"vb","password":"vbv"}]

Now my Question is how i could get the value username from employees. I have tried few things like employees[0]["username"] OR employees.username etc..

2 Answers 2

1

Because you stringify it, it becomes string so you can't access like that. Just use it as is.

Sign up to request clarification or add additional context in comments.

Comments

0

JSON.stringify(rows) only allow you to pretty print the data.

To access it you were right with employees[0]["username"]

connection.query("SELECT * from login where username='" + uname + "' and password='" + pwd + "' ", [uname, pwd], function (err, employees)
    {
        console.log("Inside server " + JSON.stringify(employees));
        console.log('Employee 1: ' + employees[0]["username"]);
    });  

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.