user5985135
user5985135

Reputation:

How to extract array on nodejs

Im making the api for showing the user info, so I write the code like this

res.json({"Status" : true , "User" : rows });

then i get the result

    {
      "Status": true,
      "User": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

But I want the result like this

    {
      "Status": true,
      "userid": 821786,
      "fullname": "undefined"
    }

How can I do this ?

I tried

res.json({"Status" : true ,"Type":"Google",  rows });

but it gives me

    {
      "Status": true,
      "rows": [
        {
          "userid": 821786,
          "fullname": "undefined",
        }
      ]
    }

I can sure that only one result will be queried so i dont want to use array

Upvotes: 1

Views: 91

Answers (1)

Cespejo
Cespejo

Reputation: 414

Try this:

var result = rows[0];
result.Status = true;
res.json(result);

Upvotes: 3

Related Questions