在node.js中,我可以向控制台打印一个日语字符,如下所示:

console.log('\u3041');

如果我有3041作为一个数字,例如,因为它是随机生成的,我如何打印相应的utf-8 sigil?
const charNumber = 3041;

// of course this doesn't work, but I need something like that:
console.log(`\u${charNumber}`);

最佳答案

通过将.fromCharCode替换为\u,可以使用0x的十六进制表示:

const charNumber = 3041;
console.log(String.fromCharCode(`0x${charNumber}`));

关于javascript - 编号为UTF-8字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56680287/

10-11 05:33