I am building a simple web app that allows users to search the stats of a player in a video game.
Here is my code
let player = [];
let proxy = "https://cors-anywhere.herokuapp.com/"
let url = proxy + "https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=Hess"
function getPlayer() {
return fetch(url)
.then((response) => response.text())
.then((data) => console.log(data));
}
getPlayer().then((playerData) => {
console.log(playerData);
playerData.push(player);
console.log(player);
});
As you can see, I am trying to console.log the response and push the response to an array player so I can later use the fecthed data in the player array to perform some other actions on.
Why is it returning undefined? Why won't my response get pushed into the player array?