0

I am calling an API and I stored its data in a local variable then also I am unable to access the data. On accesing I get the output as "undefined"

let arrOfAPI = new Map();
let i = 0;
fetch("https://www.kontests.net/api/v1/all")
  .then(res => res.json())
  .then(data => data.forEach(elem => {
    arrOfAPI.set(i++ , elem)
}));
console.log(arrOfAPI.get(23));

Output

j08691
  • 204,283
  • 31
  • 260
  • 272

0 Answers0