Mapping Nested JSON

  javascript, json

I try to mapping nested JSON in React JS.

My JSON data like this,

"beautifuldata": [
{ "id":"1", "name":"a"},
{ "id":"2", "name":"b"},
{ "id":"3", "name":"c"},
{ "id":"4", "name":"d"},
{ "id":"5", "name":"e"},
{ "id":"6", "name":"f"},
{ "id":"7", "name":"g"}]

this data came from an API. And I can write my data to the console. But everything went wrong when I try to access the inner side. For example, I want to get id from my JSON data,

I try this

[beautifuldata].map(x => console.log(x));

this code line gave all data,

[beautifuldata].map(x => console.log(x.id));

this code line gave me undefined. I want to access all data inside my JSON. What am I missing?

Source: Ask Javascript Questions

LEAVE A COMMENT