字符串比较不起作用

用户名

为什么我每次都无法匹配..这段代码有什么问题

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");
}

JSFiddle

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章