0
    function getCountryName(countryCode) {
fetch("./countryCode.json")
  .then((res) => {
    return res.json();
  })
  .then((isoCountries) => {
      console.log(countryCode)
      console.log(isoCountries);
      console.log(isoCountries.countryCode);
    if (isoCountries.countryCode) {
      return isoCountries.countryCode;
    } else {
      return countryCode;
    }
  });

} Output Below ->

IN (country code for india)

Object { AF: "Afghanistan", AX: "Aland Islands", AL: "Albania", DZ: "Algeria", AS: "American Samoa", AD: "Andorra", AO: "Angola", AI: "Anguilla", AQ: "Antarctica", AG: "Antigua And Barbuda", … }

undefined

akshay23codes
  • 19
  • 1
  • 3
  • Can you share the JSON object? – aprouja1 Mar 05 '21 at 15:25
  • 2
    [There's no such thing as a "JSON Object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – Andreas Mar 05 '21 at 15:25
  • 1
    Most likely this is a dupe of the whole async thing. Please see [How do I return the response from an aynchronous call](https://stackoverflow.com/q/14220321/438992). Please see the [How to Ask](https://stackoverflow.com/help/how-to-ask) page: there are not enough details here to understand the context of your issue. – Dave Newton Mar 05 '21 at 15:27
  • You need to do `isoCountries[countryCode]`. See duplicate reference. – trincot Mar 05 '21 at 15:37
  • @Dave, no that is not the issue here. – trincot Mar 05 '21 at 15:37
  • @trincot Ah, I see. It's the next one, though ;) – Dave Newton Mar 05 '21 at 15:50

0 Answers0