The confusing behavior of String.split():
When the split function sees a string/character that matches the search string, it would automatically replace the string with a blank string in the returned array:
'aaaaa'.split('a'); // returns ['', '', '', '', '']
But when I put it with other letters, then magically, couple blank strings disappear:
'abababa'.split('a'); // returns ['', 'b', 'b', 'b', '']
I know that it can be used to split words using
'apples are great'.split(' '); // returns ['apples', 'are', 'great']
But what about putting an extra space in between the words?
'apples are great'.split(' '); // returns ['apples', '', 'are', '', 'great']
If I wanted apples are great'.split(' ');
to return ['apples', '', '', 'are', '', '', 'great']
, what are options to make that happen?