javascriptunicodeemoji

How do I convert Unicode to emoji in JavaScript?


I have an array with Unicode data like var data = ["1F923", "1F603"]

If I use "\u{1F923}" in console, it returns an emoji, but if I use "\u{"+ data[0] +"}", it returns an error. Can anyone please help me to convert Unicode to emoji.


Solution

  • Emoji is a subset of unicode. There is no conversion from unicode to emoji necessary or possible. Just change your array to

    var data = ["\u{1F923}", "\u{1F603}"]
    

    If your input is a hex number, you can use

    String.fromCodePoint(parseInt ("1F923", 16))
    

    In HTML you can also use HTML hex entities

    "&#x" + "1F923" + ";"