0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaScript, TypeScript|大文字小文字判定

Last updated at Posted at 2023-01-24

JavaScript, TypeScriptで大文字小文字を判定する方法です。
言語によっては大文字小文字を判定する関数が備わっているものもありますが、JS, TSにはないので下記の方法を取ります。
(例えばPythonには、islower(), isupper()があります)

大文字かどうか確かめる場合
  1. 文字を大文字に変換します
  2. 変換前の文字と変換後の文字を比較します
  3. trueなら大文字、falseなら小文字です
sample.ts
const letter: string = "a";

if (letter === letter.toUpperCase()) {
    // trueの場合
    console.log("これは大文字です");
} else {
    // falseの場合
    console.log("これは小文字です");
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?