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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -