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,596
  • 6
  • 21
  • 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,336
  • 10
  • 55
  • 67
Sarfraz
  • 367,681
  • 72
  • 526
  • 573