Skip to content

Instantly share code, notes, and snippets.

Last active March 12, 2023 13:20
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Get Champion by key or by ID with the latest DDragon version (Javascript)
let championByIdCache = {};
let championJson = {};
async function getLatestChampionDDragon(language = "en_US") {
if (championJson[language])
return championJson[language];
let response;
let versionIndex = 0;
do { // I loop over versions because 9.22.1 is broken
const version = (await fetch("").then(async(r) => await r.json()))[versionIndex++];
response = await fetch(`${version}/data/${language}/champion.json`);
while (!response.ok)
championJson[language] = await response.json();
return championJson[language];
async function getChampionByKey(key, language = "en_US") {
// Setup cache
if (!championByIdCache[language]) {
let json = await getLatestChampionDDragon(language);
championByIdCache[language] = {};
for (var championName in {
if (!
const champInfo =[championName];
championByIdCache[language][champInfo.key] = champInfo;
return championByIdCache[language][key];
// NOTE: IN DDRAGON THE ID IS THE CLEAN NAME!!! It's also super-inconsistent, and broken at times.
// Cho'gath => Chogath, Wukong => Monkeyking, Fiddlesticks => Fiddlesticks/FiddleSticks (depending on what mood DDragon is in this patch)
async function getChampionByID(name, language = "en_US") {
return await getLatestChampionDDragon(language)[name];
async function main() {
const annie = await getChampionByKey(1, "en_US");
const leona = await getChampionByKey(89, "es_ES");
const brand = await getChampionByID("brand");
Copy link

iEloyB commented Mar 12, 2023

So helpful! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment