LoginSignup
2
0

More than 1 year has passed since last update.

JavaScriptでA-Zの羅列を楽に作る方法

Posted at

エクセル形式が関わる案件でたまに使うんだけどちょくちょく忘れるので備忘録

String.fromCharCodeを使う。これは文字コードのnumberをstringに変換してくれる
例えばString.fromCharCode(0x41);とすると"A"が出てくる。
これをfor文で回してあげる

index.js
for(let i = 0x41; i <= 0x5A; i++){
  console.log(String.fromCharCode(i))
}

出力

A
B
C
D
...

小文字が欲しければ0x61~0x7Aを見てあげればいい

ただしこの手法はひらがなには使えない。
0x3041: ぁ
0x3042: あ
0x3043: ぃ
0x3044: い
0x304B: か
0x304C: が
のように小文字や濁点付き文字がごっちゃに出てくる。この場合素直にあ~んまで打った方が早いだろう。

2
0
2

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
2
0