我有一个字符串,其中包含文本和许多html标签,其中包含各自的属性及其值,例如: -
我试图取出所有的标签名称并推入内部数组注释: - 我有两个自定义函数,名为trim()和null(),它删除字符串的所有空格并检查提供的参数是否为空.
var a = `
<div class="box">
<span id="box-span">
<p class="texts">very long texts goes here.</p>
<p class="texts">very long texts goes here</p>
<p class="texts">very long texts goes here</p>
</span>
</div>`;
var tags = function(string) {
var array = ['hello'];
var string = a.trim('');
var len = string.length;
for (var i = 0; i < len; i++) {
index1 = string.indexOf('>');
index2 = string.indexOf('<');
index3 = string.indexOf('/');
if (null(index1) && index1 !== -1 && null(index2) && index2 !== …Run Code Online (Sandbox Code Playgroud)我试图拆分字符串包括字符串,但空间也吐了.
我的代码: -
var a =' that i love
game1 ';
console.log(a.split(' '))
Run Code Online (Sandbox Code Playgroud)
我目前的输出如下: -
(57) ["?", "", "", "", "", "", "", "", "", "that", "i", "love?", "", "", "", "", "", "", "", "", "game1???", "", "", "", ""]
Run Code Online (Sandbox Code Playgroud)
输出我试图得到这样的东西: -
(4)[" that",'i',' love',' ?game'];
Run Code Online (Sandbox Code Playgroud)
如何以这种方式分割字符串,包括空格和换行?
javascript ×2