0

I have big chunk of array of object. I want to get something then assign it to a new property, I did this

async function t() {
  return bigChunkArr.map(async o => ({
    ...o,
    address: await getAddress(o.lat, o.lng)
  }))
}
const result = await t() //expected to be array

The problem the result is still a promise, why?

Ori Drori
  • 183,571
  • 29
  • 224
  • 209

1 Answers1

1

Map here will return an array of promises. We can use Promise.all to get the result of these promises when the return. In the code below, t will return a promise.

const t = () => {
    const promises = bigChunkArr.map(async (o) => {
        return {
            ...o,
            address: await getAddress(o.lat, o.lng)
        }
    });
    return Promise.all(promises);
}