Pingu
Pingu

Reputation: 41

Elegant way to avoid differentiating between upper - and lowercase characters ? (preferable in JavaScript)

Is there an elegant way to treat both lower- and uppercase characters the same ?

Something where

if (char == a) 

Would return true regardless of char being A or a.

Upvotes: 0

Views: 147

Answers (1)

Jack Bashford
Jack Bashford

Reputation: 44125

Just convert it to uppercase or lowercase first:

if (char.toUpperCase() == "A") {...}
// Or
if (char.toLowerCase() == "a") {...}

Upvotes: 1

Related Questions