0

I have difficult problem when I try to print out a value from a textrow in node.js.

The code console.log(data.res[0]); prints out [ TextRow { username: 'alex' } ]

So to only print out alex in this case should be easy, but I can't seem to figure it out.

I have tried printing it out by these different sorts of code.

console.log(data.res[0].username);

console.log(data.res.username);

console.log(data[0].res.username);

but these attemps either crashes the code, or prints out username as undefined.

How am I doing wrong in this?

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • 2
    If `data.res[0]` gives you `[ TextRow { username: 'alex' } ]` then that's an array. Most likely you need `data.res[0][0].username` to get the first item of the array and the `username` property from it. – VLAZ Mar 15 '21 at 09:25
  • Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – VLAZ Mar 15 '21 at 09:27
  • `data.res[0][0].username` – Anand Undavia Mar 15 '21 at 09:28

0 Answers0