LoginSignup
3
3

More than 5 years have passed since last update.

'String'.split('')は文字列を分割して、配列を作成する。

Last updated at Posted at 2013-04-15

splitは

String.split
文字列を区切ることに使用するための文字を指定します。

とあったので、区切り文字が無いと分割できないかと思いがちだが、
空文字''を区切り文字として指定すると、文字列を分割した配列が作成出来る。
ちなみに、引数を指定しないと文字列を要素とした配列が作成される。

'h,o,g,e'.split(',')//=> [ 'h', 'o', 'g', 'e' ]

'hoge'.split()//=> [ 'hoge' ]

'hoge'.split(''); //=> [ 'h', 'o', 'g', 'e' ]

3
3
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
3
3