Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
How to have each "results" (parameters) from API

that is my raw response from API call who im trying to get each "bloc" result with a .forEach

const app = express();
const axios = require('axios')

jobList = [];

app.get('/getAPIResponse', function(req, res) {
async function myFunction() {


axios.get('https://api...') 
    //res.json(body)
  .then((result) => {
    
    
    result.results.forEach((element) => {
      
      console.log(element)
      
      this.jobList.push(element)
      
    });

  })

  }
 myfunction();
});


app.listen(port, () => {
 console.log(`Example app listening at http://localhost:${port}`);
 });

but the problem is, it made me some error on my terminal

(rejection id: 2)
(node:81826) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined
    at /Users/mac/Desktop/alternatics_test/index.js:22:24
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:81826) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:81826) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined
    at /Users/mac/Desktop/alternatics_test/index.js:22:24
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(node:81826) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

to be as clear as possible results is the keyword in the api from which I would like to take each result block for insert in my "jobList"

I looked everywhere and the forEach seems to be the right technique for this...

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You are using module axios

That will return a response with axios response schema

So you have to get result like this result.data.results then you can use forEach function

about 4 years ago · Juan Pablo Isaza Denunciar

0

use result.data.results.forEach

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda