Reputation: 232
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?
Upvotes: 2
Views: 2569
Reputation: 3241
To the best of my knowledge, that is the best way to do it. Alternatively you could just ignore the first parts of the split:
URL_STRING.split('/').slice(3)
Upvotes: 2