-3

I need to separate the file path from the file name: (some codes did not work in the past) If the path is www.example.com/hi/test/home.html How would I get just www.example.com/hi/test/?

1 Answers1

2

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
Mamdouh Saeed
  • 2,232
  • 1
  • 8
  • 10
Jayce444
  • 8,009
  • 3
  • 24
  • 39