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

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