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
Post a Comment