Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

99
Views
Map over Object to get links in React

I have an API request that comes back with.

externalLinks : {
      website: {
        _links: {
          self: {
            rel: 'self',
            method: 'get',
            href: 'http://www.example.com/',
          },
        },
      },
      twitter: {
        _links: {
          self: {
            rel: 'self',
            method: 'get',
            href: 'https://twitter.com/',
          },
        },
      },
      discord: {
        _links: {
          self: {
            rel: 'self',
            method: 'get',
            href: 'https://discord.gg/',
          },
        },
      }
    };

and in my render I want to generate a link for each of the external links.

<div>
{ // Loop in here to generate links }
</div>

Whats the best way?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I'd do something like the following:

const links = (
  <div>
    <ul>
      {
        Object.entries(exLinks).reduce((str, [website, val]) => 
          str += `<a href='${val._links.self.href}'>${website}</a>`, 
        '')
      }
    </ul>
  </div>
); 

If you're specifically looking to use the map function, you can do that too:

let element = (
  <div>
    {Object.entries(exLinks).map(entry => 
      `<a href='${entry[1]._links.self.href}'>${entry[0]}</a>`
    )}
  </div>
)
about 4 years ago · Juan Pablo Isaza Report

0

You can try something like this with Object.entries

https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

const obj = {
  website: {
    _links: {
      self: {
        rel: "self",
        method: "get",
        href: "http://www.example.com/",
      },
    },
  },
  twitter: {
    _links: {
      self: {
        rel: "self",
        method: "get",
        href: "https://twitter.com/",
      },
    },
  },
  discord: {
    _links: {
      self: {
        rel: "self",
        method: "get",
        href: "https://discord.gg/",
      },
    },
  },
};

const arr = [];
for (const [key, value] of Object.entries(obj)) {
  arr.push({ ["website"]: value._links.self.href });
}

console.log(
  "websites",
  arr.map((item) => item.website)
);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!