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

Softwareentwickler

Zur Übersicht

Standort Hannover

newcubator GmbH
Bödekerstraße 22
30161 Hannover

Standort Dortmund

newcubator GmbH
Westenhellweg 85-89
44137 Dortmund