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

98
Views
Mapa sobre objeto para obtener enlaces en React

Tengo una solicitud de API que vuelve con.

 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/', }, }, } };

y en mi render quiero generar un enlace para cada uno de los enlaces externos.

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

¿Cuál es la mejor manera?

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

0

Yo haría algo como lo siguiente:

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

Si está buscando específicamente usar la función de mapa, también puede hacerlo:

 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

Puedes probar algo como esto con 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!