如何使用 javascript 动态组合从“1f628”到“\u{1f628}”的表情符号 unicode

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

我正在尝试转换一串统一的表情符号。

尝试执行此操作时出现错误:

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

SyntaxError: Invalid Unicode escape sequence

我怎样才能让它发挥作用?

String.fromCodePoint will get you the character from its numeric code point, and parseInt 将从十六进制字符串中获取数字:

var code = '1f628';
String.fromCodePoint(parseInt(code, 16)); //