así que estoy obteniendo algunos datos de PUBG Api, y colocando los datos necesarios en una matriz llamada "playerRecentStats", pero cada vez que trato de sacar esta matriz de la función, obtengo un resultado indefinido o vacío, puedo leerlo desde algunos puntos en la función, pero cada vez que trato de leerlo fuera de la función de búsqueda o general, no funciona.
Aquí está el código para el contexto.
let playerRecentStats = []; function recentMatchesPerformance() { last10Matches.map((match) => { fetch( `https://api.pubg.com/shards/${playerPlatform}/matches/${match.id}`, options ) .then((response) => response.json()) .then((data) => { data.included.forEach((player) => { if (player.type == 'participant') { if (player.attributes.stats.name == playerName) { playerRecentStats.push({ kills: player.attributes.stats.kills, dmgDone: player.attributes.stats.damageDealt, knocks: player.attributes.stats.DBNOs, date: data.data.attributes.createdAt, }); } } // console.log(playerRecentStats); This reads here! }); // console.log(playerRecentStats); This does not read here! }); }); return playerRecentStats; // This is returning an empty array! } recentStats = recentMatchesPerformance(); // I want to read the playerRecentStats Array here. console.log(playerRecentStats); // Empty Array console.log(recentStats); // Empty ArrayOjalá puedas ayudarme, gracias.