Jack Richard Jack Richard - 9 months ago 86
Javascript Question

JavaScript-How To Separate Path from File Name

I need to separate the file path from the file name:
If the path is www.example.com/hi/test/home.html
How would I get just www.example.com/hi/test/?

Answer Source

You can use substring and lastIndexOf:

a = www.example.com/hi/test/home.html
b = a.substr(0, a.lastIndexOf('/'))

// b = www.example.com/hi/test