Testing Characters in JavaScript | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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 Réponses
+ 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