JavaScript handles strings and arrays very well. Sometime its needed to get the last segment or file name of the current page URL and process it for another JavaScript/Ajax request.

Here, I would like to share a fairly easy way.

Let current page URL is

Code Example:

Get Last Segment of URL in JavaScript

For the same purpose, JavaScript array function pop() can be used.

Code Example: