Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Map through array that includes object

Below is the response coming back. I’m trying to map through the logo object so that I can grab the url, however my implementation on Object.keys is not working. What am I doing wrong?

[
  {
    "title": "Header",
    "logo": {
      "metadata": {},
      "sys": {},
      "fields": {
        "title": "Logo",
        "file": {
          "url": "xxxxxx",
          "details": {},
          "fileName": "logo.png",
          "contentType": "image/png"
        }
      }
    },
    "links": []
  }
]
{Object.keys(header.logo.fields.file).map((logo) => (
    <p>{logo.url}</p>
))}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Assuming the top-level array name is header, just do this. Note that the top-level structure is an array, so you need an index to get the object inside.

<p>{header[0].logo.fields.file.url}</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading