Need a basename function in Javascript

function basename(path) {
   return path.split("https://stackoverflow.com/").reverse()[0];
}

Breaks up the path into component directories and filename then returns the last piece (the filename) which is the last element of the array.

Leave a Comment