How to convert unicode point to Emoji || Symbol || Character

Viewed 44

I want to convert Unicode Code Points Notation like "U+1F1FA U+1F1F8" to "".

In javaScript, what I have tried so far is

String.fromCharCode(parseInt("U+1F1FA", 16));

But this doesn't work.

3 Answers

You can wrap the hex code in braces like this:

console.log('\u{1f1fa}\u{1f1f8}')

You can use the static method String.fromCodePoint() to achieve this.

const us = String.fromCodePoint('0x1F1FA', '0x1F1F8');
console.log(us);

Thanks a lot for above answers. I came with a method to convert the unicode notations to Emoji.

        function unicodeToChar(text:string) {
            const splited = text.split(" ")
            let str = ""
            for(let i = 0;i < splited.length;i++){
                splited[i] = splited[i].replace('U','0')
                splited[i] = splited[i].replace('+','x')
                str += String.fromCodePoint(parseInt(splited[i],16))
            }
            return str
        }
Related