Home > Mobile >  fetch() from url, cant access object, console.log() works
fetch() from url, cant access object, console.log() works

Time:09-28

I have the 3 following lines of code:

const response = await fetch(`https://restcountries.com/v3/alpha/${countrycode}`);
let json = await response.json();
console.log("this is my json file: ", json.borders)

The problem is, when I do this I receive in my console log undefined but I want to access the 'borders' property of the object. On the other side, if I change the third line into this:

console.log("this is my json file: ", json)

I get the full object which looks like this:

{"altSpellings": ["DE", "Federal Republic of Germany", "Bundesrepublik Deutschland"], "area": 357114, "borders": ["AUT", "BEL", "CZE", "DNK", "FRA", "LUX", "NLD", "POL", "CHE"], "capital": ["Berlin"], "cca2": "DE", "cca3": "DEU", "ccn3": "276", "cioc": "GER", "currencies": {"EUR": [Object]}, "demonyms": {"eng": [Object], "fra": [Object]}, "flag": "

  • Related