Get last path segment - Node.js File

Node.js examples for File:Path

Description

Get last path segment

Demo Code

function basenameURL(url) {
  return removeTrailingSlash(url).split("/").pop();
}
function removeLeadingSlash(url) {
  return (url[0] == "/") ? url = url.substr(1) : url;
}
function removeTrailingSlash(url) {
  return (url[url.length - 1] == "/") ? url.substr(0, url.length - 1) : url;
}

Related Tutorials