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

119
Views
spreading an array returned from an async function results in empty array?

I am attempting set a constant to an array of objects which is returned from an async function. When I log the constant, the result is as expected:

code:

const songList = songsArrayFromIdList(rehearsal.rehearsallist);
console.log(songList);

logs (as expected):

[]
0: {formtake: 'https://...
1: {userpracticed: 'do...
2: {formtake: 'https://yo...
3: {titleabbreviation: 'DPM', formtake: 'https...
length: 4
[[Prototype]]: Array(0)

However, I'd like to spread the returned array of objects into the constant in order to in create a new array reference (to later include in a React state object). But, when I spread the returned array into the constant it logs an empty array:

const songList = [...songsArrayFromIdList(rehearsal.rehearsallist)];
console.log(songList);

logs (unexpectedly):

[]
length: 0
[[Prototype]]: Array(0)

very frustrated. I feel like the obvious issue has something to do with the array returning from an async function. But, clearly the array is usable due it logging properly when not spread??

What am I missing?

Thanks in advance.

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!