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

145
Vistas
res.json is sending empty array

My function is being triggered by a post request.

I am sending an array of ids from the front end and using forEach to go over every element and send an api call to get data back and push that data into a new array.

I cant seem to access the data outside of the loop. ex. I want to res.json(array) but array shows empty. When I --> .then(participants => console.log({"sid": participants.sid})) I see the logs just fine

const listParticipants = async (req, res) => {
    const { subActServiceSid, subActAuthToken, convoServiceSid} = req.user
    const subClient = require('twilio')(subActServiceSid, subActAuthToken)
    const { data } = req.body
    const array = []
    await data.forEach(convo => {
       subClient.conversations.services(convoServiceSid)
      .conversations(convo)
      .participants
      .list({limit: 20})
      .then(participants => array.push({"sid": participants.sid}));
       
    })
    res.json(array) // this is showing empty array....
 }

this is the const {data} = req.body
[
"CH01db9e1427994dg",
"CH1b1cc2b8f5534gb",
"CH34c27e8ff76e403",
"CH363665d704ab48f",
"CH410e8d086310443",
"CH4d2ac9670d2d413",
"CH4e1ef59ac99e48c",
]
about 4 years ago · Juan Pablo Isaza
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