javascript 检查变量是否存在字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7887167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
check variable if char exist or not
提问by Rahul Singh
Possible Duplicate:
How to tell if a string contains a certain character in javascript?
Suppose I have a string in variable ex. var name="Stackoverflow"
. I want to check in this string if 'z' is exist or not? How can I check this? I don't want to find index or anything else I just want to check if value z
is exist or not.
假设我在变量 ex 中有一个字符串。var name="Stackoverflow"
. 我想检查这个字符串是否存在“z”?我该如何检查?我不想找到索引或其他任何东西,我只想检查值z
是否存在。
Suppose with code. I have a variable.
假设有代码。我有一个变量。
var deleteboxvalue = "1111111111111111111111";
if(!deleteboxvalue.indexOf('z') >= 0){
alert("0 not exist");
return false;
}