为什么我每次都无法匹配..这段代码有什么问题
var CourseDesc = 'Master of Computer Application'
var str = CourseDesc.split(" ");
alert(str[0]);
var str2 = 'Master';
if(str == str2){
alert("Matched");
}else{
alert("Not Matched");
}
有人面对吗?
String.Split方法返回包含子字符串的数组。因此,您的str
变量是数组而不是字符串。
if(str[0] == str2)
var CourseDesc = 'Master of Computer Application'
var str = CourseDesc.split(" ");
alert(str[0]);
var str2 = 'Master';
if(str[0] == str2){
alert("Matched");
}else{
alert("Not Matched");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句