0

I have the following JSON structure

{
    "posts":{
        "title 1":{
            "content":"The content",
            "url":"https://www.site.nl"
        },
        "title 2":{
            "content":"The content",
            "url":"https://www.site.nl"
        }
    }
}

I want loop through this JSON and get all data but I don't know how to get further

What I have so far is

Object.entries(JSON.parse(this.response))
//output: posts,[object Object]

Who can help me with this JavaScript loop to get the title, content and url?

1 Answers1

0

not so hard to do, especially if you read the doc

const data = 
  { "posts": 
    { "title 1": { "content": "The content", "url": "https://www.site.nl" } 
    , "title 2": { "content": "The content", "url": "https://www.site.nl" } 
    } 
  }
  
for (let title in data.posts )
  {
  console.log( title, data.posts[title].content, data.posts[title].url )
  }
Mister Jojo
  • 20,093
  • 6
  • 21
  • 40