5

I have an array of strings ['string1', 'string2'] and I want to transform each one of them into (example: blob:http://something-new) but i get a result of (2) [Promise, Promise]. How to get the resolved value?

here is the code

const results = id.map(async assetId => {
    const responseIds = await API.assets.getAssetFileById(assetId);
    let asset = responseIds.data.asset;
    const urlCreator = window.URL || window.webkitURL;
    const blobFile = await file_helper.dataUrlToBlob(asset.file);

    return asset.file = await urlCreator.createObjectURL(blobFile);
});

console.log(results) // (2) [Promise, Promise]

Expected output:

console.log(results) // (2) ['blob:http://something-new1', 'blob:http://something-new2']
Gleb Kostyunin
  • 3,743
  • 2
  • 19
  • 36
Kleav James
  • 150
  • 1
  • 3
  • 16

1 Answers1

2
Promise.all(results).then(function(urls) {
  console.log(urls);
});

You need to wait for all of the promises to resolve, then you can work with them.

Jordan Soltman
  • 3,795
  • 17
  • 31