I need to make function that returns name of champion by champions id. But first I need to search for the champion name inside of JSON file by champions id and then return the values from JSON file. Can anyone help me, please?
const champid = 21 //Champion id
console.log(champName(champid, leagueversions)) //This should return 'Miss Fortune' but retuns as: Promise { <pending> }
async function champName(champid, leagueversions)
{
const searchchamps = await axios.get(`http://ddragon.leagueoflegends.com/cdn/${leagueversions.champion}/data/en_US/champion.json`) //Getting all champions data from league
let championList = searchchamps.data.data //JSON list of champions
for (var i in championList) {
if(championList[i].key == champid) //if key value inside of json is same as champid
{
return championList[i].name //Should return name of champion
}
}
}