Given the url (string) http://stackoverflow.com/questions/ask, how could I split it up into an array that contains data like the following: questions,ask. How would I make this work for an infinite amount of slashes?
The way I am thinking of doing it would be to use URL.parse in Node.JS and then use STRING.split('/') to separate the string into an array.
Would this be the correct way to do it? Is there a quicker way?
URL.parsedoes the dirty work for you (getting thepath), leaving you the easy part. I'd say splitting by/is definitely a fine way to go to get each "sub-page into an array". You could of course use a regular expression, but I feel like it's more straightforward/readable with thesplit