Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 编号为UTF-8字符_Javascript_Node.js_Utf 8 - Fatal编程技术网

Javascript 编号为UTF-8字符

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

在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
,可以将十六进制表示法与
.fromCharCode
一起使用:

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