I have a url like http://www.example.com/blah/th.html
I need a javascript function to give me the \'th\' value from that.
All my urls have the same format (2
This should work for all cases
function getFilenameFromUrl(url) { const pathname = new URL(url).pathname; const index = pathname.lastIndexOf('/'); return (-1 !== index) ? pathname.substring(index + 1) : pathname; }