toLowerCase inside map function

I want to get an image (countryflag) returned right by my country name. The problem is that I get returned iso2 in capital letters and the API only accepts lowercase letters.

As of now the url in the code is returned like: https://disease.sh/assets/img/flags/LT.png and I need it to return https://disease.sh/assets/img/flags/lt.png (all lowercase letters) instead.

return (
        <ul>
          {data.map(d => (
            <li key={d.countryInfo._id}>
              <img src={"https://disease.sh/assets/img/flags/" + d.countryInfo.iso2.toLowerCase() + ".png"}></img>
              {d.country} has total {d.cases} different cases as of today.
            </li>
          ))}
        </ul>

I have been trying to use .toLowerCase() in the end of d.countryInfo.iso2 (since it’s a String) but then I get TypeError: d.countryInfo.iso2 is null

21 thoughts on “toLowerCase inside map function”

  1. Hi I am so happy I found your web site, I really found you
    by mistake, while I was searching on Yahoo for something else, Nonetheless I am here now and would just like to say cheers for a fantastic post and a all round interesting blog (I also love the theme/design), I don’t
    have time to read it all at the minute but I have bookmarked it and also added your RSS feeds, so
    when I have time I will be back to read much more, Please
    do keep up the fantastic jo. https://hhydroxychloroquine.com/

    Reply

Leave a Comment