2.2.2022 |

How To: Convert country codes to flag emojis

If you want to show country flags and you only have the country code available there is simple conversion algorithm for that:

function getFlagEmoji(countryCode) {
  const codePoints = countryCode
    .toUpperCase()
    .split('')
    .map(char =>  127397 + char.charCodeAt());
  return String.fromCodePoint(...codePoints);
}

This code basically shifts the country code characters to the correct position of the emoji in the unicode space.

Source: https://dev.to/jorik/country-code-to-flag-emoji-a21

Sven Röttering
Zur Übersicht

Mehr vom DevSquad...

Jörg Herbst

Strings and logic in javascript

Sven Röttering

npkill - the ultimate tool to free up disk space