どうも、ちょげ(@chogetarou)です。
split()を使って文字列(string)を1文字ずつに分割した配列に変換する方法を紹介します。
方法

split()を使って文字列(string)を1文字ずつに分割した配列に変換するには、引数を使います。
まず、文字列からsplit()を呼び出します。
そして、split()の引数に、空文字を指定します。
const result: string[] = text.split('')
上記のsplit()は、呼び出した文字列(string)を1文字ずつに分割した配列に変換します。
使用例
const text: string = "Hello,World"
const result: string[] = text.split('')
console.log(result)
出力:
["H", "e", "l", "l", "o", ",", "W", "o", "r", "l", "d"]
コメント