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

269
Views
¿Por qué tengo problemas con esta llamada axios?

Quiero recibir 10 llamadas, cada llamada a este punto final me devuelve un solo elemento, así que usé axios en un bucle for.

En la llamada axios, presiono en la matriz vacía la respuesta. datos, pero por problemas de tiempo (creo) si consuelo. tiene objetos dentro, pero no parecen ser parte de la matriz.

Además, si trato de console.log (wordsArray [0]) fuera del ciclo for, obtengo undefined.

¿Qué tiene de malo el código?

 let wordsNumber = 10; let wordsArray = []; for(i = 0; i < wordsNumber; i++) { axios.get('https://flynn.boolean.careers/exercises/api/random/word') .then( res => { wordsArray.push( res.data ) // If I log the wordsArray here, inside the for loop, I get what I need. // But obviously I need this to be outside of the loop. // console.log( wordsArray ) }) .catch( err => { console.log( err ); }); } // logs an apparently empty array that can be opened, it has 10 objects inside console.log( wordsArray ) // is undefined console.log( wordsArray[0] )

Este es el HTML, solo por mostrarte el CDN de axios

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="script.js" defer></script> <title>Project</title> </head> <body> </body> </html>
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!