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

126
Views
convertir la promesa de retorno JSON en una matriz de objetos

Mi promesa devuelve un JSON como este:

 '[ {"amazing data": "hello", "amazing again": "yep"}, {"amazing data": "hello", "amazing again": "yep"}]'

Me gustaría devolver una matriz de objetos:

 [ {"amazing data": "hello", "amazing again": "yep"}, {"amazing data": "hello", "amazing again": "yep"} ]

Me gustaría acceder a él de esta manera porque puedo trabajar con reduce después de que regrese la promesa.

Mi código:

 const amazingPromise = await getData().then((data) => { return data }) const prodArray = Array.from(amazingPromise.reduce((acc, o) => { Object.entries(o) .forEach(([k, v]) => { if(!acc.has(k)) acc.set(k, [k]) acc.get(k).push(Array.isArray(v) ? v.join(' | ') : v) }) return acc }, new Map()).values())

Cualquier ayuda será genial. Gracias.

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

0

Si su proyecto es un proyecto web, puede usar react.State() para resolver esto. Por ejemplo, en mis proyectos, uso el estado para guardar los resultados de una solicitud de API como su ejemplo.

 const App = ()=>{ const[array, setArray] = useState([]); //Init the array as a empty array useEffect( ()=>{ const RequestAPI = async ()=>{ const URL = "https://..."; const response = await fetch(URL); const newArray = await response.json(); setArray(newArray); }; RequestAPI(); },[]); return ( {array.map(item => <ComponentItem /> ) } }

Intente usar algo similar a las funciones de estado y asíncronas en su proyecto como sea posible

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!