如何使用 Javascript 渲染多代码点表情符号

plm*_*k61 1 javascript emoji

我正在尝试在聊天应用程序中渲染表情符号,但无法让由多个部分构建的表情符号正常工作。

例如:

作品26f9的代码点Person with Ball

const emoji = String.fromCodePoint('0x26f9');
Run Code Online (Sandbox Code Playgroud)

26f9-fe0f-200d-2640-fe0f对于Woman bouncing ball不起作用

const emoji = String.fromCodePoint('0x26f9-fe0f-200d-2640-fe0f');
Run Code Online (Sandbox Code Playgroud)

plm*_*k61 5

弄清楚了:

const codePointString = '26f9-fe0f-200d-2640-fe0f';

const emoji = codePointString.split('-').map((codePoint) => (
  String.fromCodePoint(`0x${codePoint}`)
)).join('');
Run Code Online (Sandbox Code Playgroud)