Jack Richard Jack Richard - 1 month ago 19
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

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