arrays - Simple JavaScript Split Function -


i'm questioning why got following output code:

'willie'.split(/[i-l]{1}/); // [ 'w', '', '', '', 'e' ] 

i expecting ['w', 'e']. i'm not sure why it's inserting holes in array.

you splitting on single letter, each illi considered separator, , string splits follows:

 w     l   l     e # w   ""  ""  ""  e # if there's no content between separators, empty string in place  # or csv string w,,,,e split on comma ? 

try using greedy quantifier + match pattern long can, illi considered 1 separator:

console.log('willie'.split(/[i-l]+/));


Comments

Popular posts from this blog

python - What's the Pythonic way to report nonfatal errors in a parser? -

angular - Converting AngularJS deffered promise to AngularX observable for JSOM -

php - curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to domain.com:443 -