[SOLVED] js function to get filename from url

Issue

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 letter filenames, with .html extension).

I want it to be a safe function, so if someone passes in an empty url it doesn’t break.

I know how to check for length, but I should be checking for null to right?

Solution

var filename = url.split('/').pop()

Answered By – user2492653

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *