Jack Richard Jack Richard - 7 months ago 81
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/?


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