问题描述
我正在努力进行数组搜索,其中包含一段必须在其中包含反斜杠的文本。我尝试includes('');
否定includes('');
,也尝试使用indexOf('')
类似。
我有一个简单的数组,最多包含四个值;通常有两个,如下所示:
{tks: Array(2)}
tks: Array(2)
0: "https://mycoolwebsite.net/arcgis/rest/services"
1: "https://mycoolwebsite.com/arcgis/rest/services"
length: 2
__proto__: Array(0)
__proto__: Object
以下是我要执行的简单检查:我对*includes*
'wdt'
进行的第二次检查似乎可以正常工作,因此 我认为它带有反斜杠。无论如何,我能解决这个问题吗? 我很困惑为什么我的if
和else
都使用反斜杠在下面的第一张支票上都被击中了...我在上面加上了否定else
进行双重检查..在else
中有无选择,总是会命中else
。
// right before doing the search I am building the array,just to add more context
for (let i = 0; i < coolObj.length; i++) {
if (coolObj[i].url){
tr = coolObj[i].url;
tks.push(tr);
console.log({tks});
}
}
console.log({tks}); // consoles as I have included above ^
if (tks.includes('/arcgis/rest/services')) {
console.log({tks});
} else if (!tks.includes('/arcgis/rest/services')) {
console.log({tks});
console.log('does not include correct url');
aT = '/arcgis/rest/services';
lP = false;
filterAt(aT);
}
if (tks.includes('wdt')) {
console.log({tks});
}else {
console.log({tks});
wT = 'wdt';
filterWt(wT);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)