I\'m trying to perform the following action on a string :
\"/\";
Split the string into an array on / and .pop() off the last element. Note, that you will first need to strip off a trailing slash if there is one.
var locationstring = window.location.pathname;
// replace() the trailing / with nothing, split on the remaining /, and pop off the last one
console.log(locationstring.replace(/\/$/, "").split('/').pop());
If in the case of a URL like /path/stuff/here/ where you have the trailing /, if that case should return an empty string rather than here, modify the above to remove the .replace() from the call chain. I assumed you would want the last component regardless of a trailing slash, but may have incorrectly assumed.
console.log(locationstring.split('/').pop());