I have a string path1/path2
I need to get the values of path1 and path2.
how can i do it?
And what about getting the same from such string http://www.somesite.com/#path1/path2?
Thanks
The plain JavaScript String object has a split method.
'path1/path2'.split('/')
'http://www.somesite.com/#path1/path2'.split('#').pop().split('/')
-> ['path1', 'path2']
However, for the second case, it's generally not a good idea to do your own URL parsing via string or regex hacking. URLs are more complicated than you think. If you have a location object or an <a> element, you can reliably pick the parts of the URL out of it using the protocol, host, port, pathname, search and hash properties.