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

177
Views
Reaccionar: ¿cómo analizar la matriz mientras se recupera?

No obtengo la matriz de la API express .

En Express Code, contiene dos headArr principales : headArr y titleArr para enviar como respuesta .


Código expreso:

 app.use(cors()); app.use(express.json()); app.post('/api/v1', (request, response) => { let headArr = [{ head: 'head 1' }, { head: 'head 1' }]; let titleArr = [{ title: 'title 1'}, { title: 'title 1' }]; const data = request.body; if (data.term == 'head') { response.send({ data: headArr }); //sending the headArr } else if (data.term == 'title') { response.send({ data: titleArr }); //sending the titleArr } }); app.listen(8080);

CÓDIGO ReactJS:

 function fetchData() { const sender = { "term": "title" }; //requesting the term title let result = await fetch(`http://localhost:8080/api/v1`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, body: JSON.stringify(sender) }); let output = await result.json(); console.log(output); // Output: {data: Array(0)}. Not getting Array here. } useEffect(() => { fetchData(); }, []);

Salida de consola: FrontEnd

 {data: Array(0)} //I got the response. But not that array.

Esto lo puedes ver claramente aquí. Obtuve una respuesta JSON completa del servidor como {data: Array(0)} .

¿Cómo obtengo esa matriz de head y title ?

about 4 years ago · Juan Pablo Isaza
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!