我有这个 javascript 代码:
if (fromState.name == "home.subjects.subject.exams.exam.tests.test" &&
toState.name == "home.subjects.subject.exams.exam.tests") {
tes.test.current = false;
tes.test = null;
}
我知道我可以在这里做一个简单的匹配:
toState.name == "home.subjects.subject.exams.exam.tests"
检查 toState 名称。
但是我如何检查 toState.name 是否不包含字符串:
"home.subjects.subject.exams.exam.tests" ?
例如 toStateName 可以是:
"home" or "home.access" or "home.city"
最佳答案
这个的 ES6 版本是(查看 Allison 的回答):
!str1.includes(str2)
最初接受的答案是:
您正在寻找indexOf
var x = "home.subjects.subject.exams.exam.tests";
console.log(x.indexOf('subjects')); // Prints 5
console.log(x.indexOf('state')); // Prints -1
关于javascript - 如何检查一个字符串不包含另一个字符串的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35355920/