One method I am familiar with for splitting a string involves using the .split() method, like so:
function split(txt) {
return txt.split(' ');
}
When executed, this function would return ['hello', 'world']
if provided with the value "hello world"
.
However, my goal is to split the string in the same manner (by spaces), but instead of combining them into a single array, I aim to separate each word into its own array without having prior knowledge of the string's length or the number of spaces present.
For instance, the desired output would be [['hello'], ['world']]