Javascript 编号为UTF-8字符
在Node.js中,我可以在控制台上打印一个日语字符,如下所示:Javascript 编号为UTF-8字符,javascript,node.js,utf-8,Javascript,Node.js,Utf 8,在Node.js中,我可以在控制台上打印一个日语字符,如下所示: console.log('\u3041'); 如果我有3041作为一个数字,例如,因为它是随机生成的,我如何打印相应的UTF-8信号 const charNumber = 3041; // of course this doesn't work, but I need something like that: console.log(`\u${charNumber}`); 通过将\u替换为0x,可以将十六进制表示法与.fr
console.log('\u3041');
如果我有3041作为一个数字,例如,因为它是随机生成的,我如何打印相应的UTF-8信号
const charNumber = 3041;
// of course this doesn't work, but I need something like that:
console.log(`\u${charNumber}`);
通过将
\u
替换为0x
,可以将十六进制表示法与.fromCharCode
一起使用:
const charNumber=3041;
log(String.fromCharCode(`0x${charNumber}`))代码>