0

so im trying to get some data to the client side, but it is arriving empty, since everytime i try to get the data returned from the fetch its giving Promise { }.

Also, this async map function is inside of another async function called default, if that helps.


async function default(){


const result = last10Matches.map(async (match) => {
      const matchurl = `https://api.pubg.com/shards/${playerPlatform}/matches/${match.id}`;
      const matchresponse = await fetch(matchurl, options);
      const matchdata = await matchresponse.json();

      matchdata.included.forEach((player) => {
        if (
          player.type == 'participant' &&
          player.attributes.stats.name == playerName
        ) {
          playerRecentStats.push({
            kills: player.attributes.stats.kills,
            dmgDone: player.attributes.stats.damageDealt,
            knocks: player.attributes.stats.DBNOs,
            date: matchdata.data.attributes.createdAt,
          });
        }
      });
      // console.log(playerRecentStats); // This does log the correct data here.

      return playerRecentStats;
    });

    console.log(result); // This here returns   Promise { <pending> }

/*
// i Also tried this below. with an empty result whatsoever.
async () => {
      console.log(await result);
    };
*/

}

Thanks in advance

  • Actually, your map function is returning an array of promises. So you use `await Promise.all(result)` or `Promise.all(result).then(...)` – Steven Spungin May 01 '22 at 01:28

0 Answers0