Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compose emoji unicode dynamically from "1f628" to "\u{1f628}" with javascript

I'm trying to convert a unified string of emoji.

Getting error when trying to do this:

var code = '1f628'
`\u{${code}}`

SyntaxError: Invalid Unicode escape sequence

How can I make it work?

like image 544
Ilya Libin Avatar asked Dec 24 '22 09:12

Ilya Libin


1 Answers

String.fromCodePoint will get you the character from its numeric code point, and parseInt will get you the number from a hex string:

var code = '1f628';
String.fromCodePoint(parseInt(code, 16)); // 😨
like image 68
AuxTaco Avatar answered Dec 28 '22 16:12

AuxTaco