+ 3

Testing Characters in JavaScript

How do you test if a specific character is in a string in JavaScript?

20th Mar 2018, 10:04 PM
Leroy Jenkins
Leroy Jenkins - avatar
2 Answers
+ 5
Check if the indexOf() function does not return -1 if(theString.indexOf(theCharacter) != -1){ Character in string }
20th Mar 2018, 10:15 PM
Ariela
Ariela - avatar
+ 2
var=theString.indexOf(theChracter) will return the index of theCharacter also if it exists, and can take Regular expressions too.
20th Mar 2018, 10:58 PM
Mike Choy
Mike Choy - avatar