Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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 如何删除&;nbsp;来自json数据,并在React应用程序中显示纯文本_Javascript_Regex - Fatal编程技术网

Javascript 如何删除&;nbsp;来自json数据,并在React应用程序中显示纯文本

Javascript 如何删除&;nbsp;来自json数据,并在React应用程序中显示纯文本,javascript,regex,Javascript,Regex,我已将json数据检索到我的react本机应用程序中。我已经用这段代码删除了html标记 const regex = /(<([^>]+)>)/gi; const result = params.matan.replace(regex, ""); const regex=/(]+>)/gi; const result=params.matan.replace(regex,“”); 但我仍然可以看到或段落之间的空格 如何从中删除此。还需要在我的正则表达式中添加什么来删除 如果

我已将json数据检索到我的react本机应用程序中。我已经用这段代码删除了html标记

const regex = /(<([^>]+)>)/gi;
const result = params.matan.replace(regex, "");
const regex=/(]+>)/gi;
const result=params.matan.replace(regex,“”);
但我仍然可以看到
或段落之间的空格

如何从中删除此
。还需要在我的正则表达式中添加什么来删除


如果使用Jquery,请解析HTML

jQuery.parseHTML()

我宁愿创建一个HTML元素,将HTML分配给它的
innerHTML
,然后读取
innerText

const html = params.matan // your HTML code
const el = document.createElement('div')
el.innerHTML = html
const text = el.innerText
对于HTML,如下所示

<p>Hello&nbsp;World</p>

<p>Test 123</p>

OP正在使用react,所以一个简单的js解决方案将不起作用。我使用的是react native而不是react js。如何在react native中实现它
Hello World

Test 123