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

144
Views
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
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!