0

Right now I am getting a list of 10 url's from a promise from firebase and I then logging them to the console. What I would like to do is store the list in an object but I don't know how to return it from the promise to use elsewhere in my code.

I tried array.push as well as return obj but that doesn't seem to work well.

const multipleurls = await Promise.all([urlRef.getDownloadURL()])
  .then((data) => data.forEach(function (obj){
    console.log(obj) // this is logging all the values so i know the promise fine.
  }))

UPDATE:: I took away the object multiple urls and left it as a function and then i returned obj and it worked.

Evan
  • 11
  • 2
  • I don't think the marked duplicate is correct. `Promise.all` returns an array of resolved promises. What is the issue? – Drew Reese Jan 13 '23 at 06:05
  • @DrewReese yeah, I can't seem to do anything but log the array of promises. I'd like to save them to a react hook – Evan Jan 13 '23 at 15:56
  • In your code, are you *really* only `Promise.all`-ing a single promise (*i.e. `Promise.all([urlRef.getDownloadURL()])`*)? `Promise.all` returns an array of resolved Promise objects, you've named it `data`. Is it that you want to return *this* `data` array? Can you [edit] your post to include some example response data from `urlRef.getDownloadURL()`, and what you expect `multipleurls` result value to be? – Drew Reese Jan 13 '23 at 17:23
  • So basically @DrewReese the promise.all is something I'm pretty clear about.( I know what it's intended to do but it is working in my code so unless you know a better way I'm sticking with it) I'd like to not just log the 'obj' but rather carry the obj outside of it's current scope of the (the promise.all). In summation, basically I have a function that logs the result to a console but I cannot seem to log the object outside of the function to use elswhere – Evan Jan 13 '23 at 17:47
  • I see, I thought there was more to your code. Just return the resolved value. I think your code could be as simple as `const multipleurls = await urlRef.getDownloadURL();`. If that's all you need to do then I agree with the duplicate. – Drew Reese Jan 13 '23 at 17:48

0 Answers0