3

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.

Suppose with code. I have a variable.

var deleteboxvalue = "1111111111111111111111";
if(!deleteboxvalue.indexOf('z') >= 0){
alert("0 not exist");
return false;
}
Community
  • 1
  • 1
Rahul Singh
  • 1,614
  • 6
  • 22
  • 39

1 Answers1

9

You can use indexOf like this:

var name = "Stackoverflow"
var charExists = (name.indexOf('z') >= 0) ? true : false;
alert(charExists);

Or just (as pointed out by @Felix Kling):

var charExists = (name.indexOf('z') >= 0);
Some Guy
  • 15,854
  • 10
  • 58
  • 67
Sarfraz
  • 377,238
  • 77
  • 533
  • 578