0

I retrieved the data from the database which was in [object Object].

I usually convert these data using JSON.parse but it did not working so, I tried JSON.stringify but the data now it's like

[{"station" : "NewYork"}, {"station" : "Toronto"}]

Now I don't know how to convert this data into an array object and access it. I need only object entries but I don't know how to access it.

If it is declared to var data I need it like data[0]['station'] to access but I couldn't do it.

6
  • 1
    Try data[0]['station'] without JSON.stringify or JSON.parse Commented May 24, 2020 at 11:37
  • No, Initially it's in this format [{object Object},{object Object}] so I converted, I tried even your method it's showing undefined. Commented May 24, 2020 at 11:51
  • [object object] is default serialization of an object. more Commented May 24, 2020 at 11:53
  • I retrieved the data from the database: How? From an API response? How does your API respose look in browser? It should look something like this. Commented May 24, 2020 at 11:57
  • I'm getting a response like {"message":[{"station_name":"Hebbal"},{"station_name":"Jalahalli"},{"station_name":"Malleshwaram"},{"station_name":"Peenya"},{"station_name":"R.T.Nagar"},{"station_name":"Rajajinagar"}]} @AjeetShah Commented May 24, 2020 at 12:08

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.