Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.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 奇怪的unicode符号,无法解析int,获取NaN_Javascript_Unicode - Fatal编程技术网

Javascript 奇怪的unicode符号,无法解析int,获取NaN

Javascript 奇怪的unicode符号,无法解析int,获取NaN,javascript,unicode,Javascript,Unicode,与本主题类似- 我有一个HTML实体数组(自定义字体),如下所示: const arr = ['crop_&#x31;&#x36;_&#x39;', 'computer', '&#x33;d_rotation', '&#xf100;']; 我唯一能够成功打印的是通过执行以下操作: render() { return <span> String.fromCodePoint(parseInt(arr[0].replace(/

与本主题类似-

我有一个HTML实体数组(自定义字体),如下所示:

const arr = ['crop_&#x31;&#x36;_&#x39;', 'computer', '&#x33;d_rotation', '&#xf100;'];
我唯一能够成功打印的是
通过执行以下操作:

render() {
    return <span> String.fromCodePoint(parseInt(arr[0].replace(/&#x|;/g,''),16)) </span>
}
render(){
返回字符串.fromCodePoint(parseInt(arr[0].replace(/&#x |;/g',),16))
}
但是,其他人会抛出如下错误:

const arr = ['crop_&#x31;&#x36;_&#x39;', 'computer', '&#x33;d_rotation', '&#xf100;'];
帕森特是南 此处的某些\u编号\u超出了String.fromCodePoint的范围


String.fromCodePoint和parseInt还有其他方法吗?

当然,正确的解决方案是不生成包含HTML实体的JS字符串文本-JS直接支持unicode-但如果您坚持以下方法

您当前的尝试似乎仅在整个字符串是单个实体时有效,使用
replace
删除非整数部分,然后获得单个字符的代码。如果字符串包含普通字符和多个实体,则这显然不起作用。在这种情况下,您需要用字符串中的unicode字符替换每个实体:

arr[0].replace(/&#x([0-9a-f]+);/gi, (_, code) => String.fromCodePoint(parseInt(code, 16)))

请将准确的输入、所需的输出、您尝试的解决方案以及您的问题的清晰描述与代码一起发布。更新@Bergi.Oooooh,duhh shoot。我没有意识到字符串可以是unicode。嘘。谢谢